@rnacanvas/draw.svg 4.1.0 → 4.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -51,6 +51,40 @@ texts.toArray()[0].domNode === text1; // true
51
51
  texts.toArray()[1].domNode === text2; // true
52
52
  ```
53
53
 
54
+ ## `class Text`
55
+
56
+ Wraps an SVG text element.
57
+
58
+ ### `readonly domNode`
59
+
60
+ The wrapped SVG text element.
61
+
62
+ ```javascript
63
+ var domNode = document.createElementNS('http://www.w3.org/2000/svg', 'text');
64
+
65
+ var text = new Text(domNode);
66
+
67
+ text.domNode === domNode; // true
68
+ ```
69
+
70
+ ### `shift()`
71
+
72
+ Shifts the text element by the specified vector.
73
+
74
+ Modifies the `x` and `y` attributes (rather than the `transform` or `dx` and `dy` attributes, for instance).
75
+
76
+ The `x` and `y` attributes of descendent `tspan` elements are also modified (if present).
77
+
78
+ ```javascript
79
+ text.domNode.setAttribute('x', '10');
80
+ text.domNode.setAttribute('y', '20');
81
+
82
+ text.shift(5, -5);
83
+
84
+ text.domNode.getAttribute('x'); // '15'
85
+ text.domNode.getAttribute('y'); // '15'
86
+ ```
87
+
54
88
  ## `class Path`
55
89
 
56
90
  Wraps an SVG path element.
@@ -67,6 +101,20 @@ var path = new Path(domNode);
67
101
  path.domNode === domNode; // true
68
102
  ```
69
103
 
104
+ ### `shift()`
105
+
106
+ Shifts the path by the specified vector.
107
+
108
+ (Modifies the `d` attribute directly rather than the `transform` attribute, for instance.)
109
+
110
+ ```javascript
111
+ path.domNode.setAttribute('d', 'M 0 0 L 10 10');
112
+
113
+ path.shift(5, -5);
114
+
115
+ path.domNode.getAttribute('d'); // 'M5 -5L15 5'
116
+ ```
117
+
70
118
  ### `closestPoint()`
71
119
 
72
120
  Calculates and returns the closest point along the path to a given point
@@ -0,0 +1,10 @@
1
+ export declare class LengthList {
2
+ #private;
3
+ constructor(target: SVGLengthList);
4
+ isEmpty(): boolean;
5
+ /**
6
+ * Adds the specified offset to every length in the list.
7
+ */
8
+ shift(offset: number): void;
9
+ }
10
+ //# sourceMappingURL=LengthList.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LengthList.d.ts","sourceRoot":"","sources":["../src/LengthList.ts"],"names":[],"mappings":"AAAA,qBAAa,UAAU;;gBAGT,MAAM,EAAE,aAAa;IAIjC,OAAO,IAAI,OAAO;IAIlB;;OAEG;IACH,KAAK,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;CAO5B"}
package/dist/Path.d.ts CHANGED
@@ -1,6 +1,12 @@
1
1
  export declare class Path {
2
2
  readonly domNode: SVGPathElement;
3
3
  constructor(domNode: SVGPathElement);
4
+ /**
5
+ * Shifts the path by the specified vector.
6
+ *
7
+ * (Modifies the `d` attribute directly rather than the `transform` attribute, for instance.)
8
+ */
9
+ shift(dx: number, dy: number): void;
4
10
  /**
5
11
  * Returns the closest point along the path to the given point
6
12
  * (as well as the length along the path that the closest point is at).
@@ -1 +1 @@
1
- {"version":3,"file":"Path.d.ts","sourceRoot":"","sources":["../src/Path.ts"],"names":[],"mappings":"AAEA,qBAAa,IAAI;IACH,QAAQ,CAAC,OAAO,EAAE,cAAc;gBAAvB,OAAO,EAAE,cAAc;IAE5C;;;;;OAKG;IACH,YAAY,CAAC,CAAC,EAAE,KAAK;;;;;CAmDtB;AAED,KAAK,KAAK,GAAG;IACX,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACX,CAAC"}
1
+ {"version":3,"file":"Path.d.ts","sourceRoot":"","sources":["../src/Path.ts"],"names":[],"mappings":"AAIA,qBAAa,IAAI;IACH,QAAQ,CAAC,OAAO,EAAE,cAAc;gBAAvB,OAAO,EAAE,cAAc;IAE5C;;;;OAIG;IACH,KAAK,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,IAAI;IAMnC;;;;;OAKG;IACH,YAAY,CAAC,CAAC,EAAE,KAAK;;;;;CAmDtB;AAED,KAAK,KAAK,GAAG;IACX,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACX,CAAC"}
package/dist/Text.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ export declare class Text {
2
+ readonly domNode: SVGTextElement;
3
+ constructor(domNode: SVGTextElement);
4
+ /**
5
+ * Shifts the text element by the specified vector.
6
+ *
7
+ * Modifies the `x` and `y` attributes (rather than the `transform` attribute, for instance).
8
+ *
9
+ * The `x` and `y` attributes of descendent `tspan` elements are also modified (if present).
10
+ */
11
+ shift(dx: number, dy: number): void;
12
+ }
13
+ //# sourceMappingURL=Text.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Text.d.ts","sourceRoot":"","sources":["../src/Text.ts"],"names":[],"mappings":"AAEA,qBAAa,IAAI;IACH,QAAQ,CAAC,OAAO,EAAE,cAAc;gBAAvB,OAAO,EAAE,cAAc;IAE5C;;;;;;OAMG;IACH,KAAK,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,IAAI;CAgBpC"}
package/dist/index.d.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  import { Texts } from './Texts';
2
2
  export { Texts };
3
+ import { Text } from './Text';
4
+ export { Text };
3
5
  import { Path } from './Path';
4
6
  export { Path };
5
7
  import { AbstractPath } from './AbstractPath';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,KAAK,EAAE,CAAC;AAEjB,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,IAAI,EAAE,CAAC;AAEhB,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,CAAC;AAExB,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,CAAC;AAEzB,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,CAAC;AAEtB,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,CAAC;AAE5B,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,OAAO,EAAE,CAAC;AAEnB,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,EAAE,uBAAuB,EAAE,CAAC;AAEnC,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EAAE,qBAAqB,EAAE,CAAC;AAEjC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,CAAC;AAExB,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,CAAC;AAEtB,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,QAAQ,EAAE,CAAC;AAEpB,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,QAAQ,EAAE,CAAC;AAEpB,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,oBAAoB,EAAE,CAAC;AAEhC,OAAO,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAC1E,OAAO,EAAE,0BAA0B,EAAE,CAAC;AAEtC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,KAAK,EAAE,CAAC;AAEjB,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,IAAI,EAAE,CAAC;AAEhB,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,IAAI,EAAE,CAAC;AAEhB,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,CAAC;AAExB,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,CAAC;AAEzB,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,CAAC;AAEtB,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,CAAC;AAE5B,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,OAAO,EAAE,CAAC;AAEnB,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,EAAE,uBAAuB,EAAE,CAAC;AAEnC,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EAAE,qBAAqB,EAAE,CAAC;AAEjC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,CAAC;AAExB,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,CAAC;AAEtB,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,QAAQ,EAAE,CAAC;AAEpB,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,QAAQ,EAAE,CAAC;AAEpB,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,oBAAoB,EAAE,CAAC;AAEhC,OAAO,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAC1E,OAAO,EAAE,0BAA0B,EAAE,CAAC;AAEtC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,CAAC"}
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports["draw.svg"]=e():t["draw.svg"]=e()}(this,()=>(()=>{var t={725(t){t.exports=(()=>{var t={986:function(t){t.exports=(()=>{"use strict";var t={d:(e,r)=>{for(var n in r)t.o(r,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:r[n]})},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 n(t){return r(t)/t.length}function i(t){t.sort(function(t,e){return t-e})}t.r(e),t.d(e,{areWithin:()=>f,average:()=>n,degrees:()=>m,isBetweenExclusive:()=>h,isBetweenInclusive:()=>l,max:()=>c,mean:()=>n,median:()=>s,min:()=>u,radians:()=>p,sortNumbers:()=>i,sortNumbersAscending:()=>i,sortNumbersDescending:()=>d,sortedNumbers:()=>a,sortedNumbersAscending:()=>a,sortedNumbersDescending:()=>g,sum:()=>r});var o=function(t,e,r){if(r||2===arguments.length)for(var n,i=0,o=e.length;i<o;i++)!n&&i in e||(n||(n=Array.prototype.slice.call(e,0,i)),n[i]=e[i]);return t.concat(n||Array.prototype.slice.call(e))};function a(t){var e=o([],t,!0);return i(e),e}function s(t){if(0==t.length)return NaN;var e=a(t);if(e.length%2!=0)return e[Math.floor(e.length/2)];var r=e.length/2,i=r-1;return n([e[r],e[i]])}function u(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 c(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 l(t,e,r){return t>=e&&t<=r}function h(t,e,r){return t>e&&t<r}function f(t,e,r){return Math.abs(t-e)<=r}function d(t){i(t),t.reverse()}function g(t){var e=a(t);return e.reverse(),e}function m(t){return t*(180/Math.PI)}function p(t){return t*(Math.PI/180)}return e})()},854:function(t){t.exports=(()=>{"use strict";var t={d:(e,r)=>{for(var n in r)t.o(r,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:r[n]})},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 n(t){return r(t)&&Number.isFinite(t)}function i(t){return r(t)&&!Number.isFinite(t)}function o(t){return n(t)&&t>0}function a(t){return n(t)&&t>=0}function s(t){return"string"==typeof t}function u(t){return null==t}function c(t){return"object"==typeof t&&null!==t}function l(t){return Array.isArray(t)}return t.r(e),t.d(e,{isArray:()=>l,isFiniteNumber:()=>n,isNonFiniteNumber:()=>i,isNonNegativeFiniteNumber:()=>a,isNonNullObject:()=>c,isNullish:()=>u,isNumber:()=>r,isPositiveFiniteNumber:()=>o,isString:()=>s}),e})()},30:function(t){t.exports=(()=>{"use strict";var t={d:(e,r)=>{for(var n in r)t.o(r,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:r[n]})},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 Math.pow(Math.pow(t.x,2)+Math.pow(t.y,2),.5)}function n(t){return Math.atan2(t.y,t.x)}return t.r(e),t.d(e,{direction:()=>n,magnitude:()=>r}),e})()}},e={};function r(n){var i=e[n];if(void 0!==i)return i.exports;var o=e[n]={exports:{}};return t[n].call(o.exports,o,o.exports,r),o.exports}r.d=(t,e)=>{for(var n in e)r.o(e,n)&&!r.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},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 n={};return(()=>{"use strict";r.r(n),r.d(n,{areWithin:()=>s,centroid:()=>d,deepCopy:()=>o,direction:()=>h,displaced:()=>c,displacement:()=>u,distance:()=>a,isFinitePoint:()=>i,isPoint:()=>e,midpoint:()=>g});var t=r(854);function e(e){return(0,t.isNonNullObject)(e)&&(0,t.isNumber)(e.x)&&(0,t.isNumber)(e.y)}function i(r){return e(r)&&(0,t.isFiniteNumber)(r.x)&&(0,t.isFiniteNumber)(r.y)}function o(t){return{x:t.x,y:t.y}}function a(t,e){var r=e.x-t.x,n=e.y-t.y;return Math.pow(Math.pow(r,2)+Math.pow(n,2),.5)}function s(t,e,r){return a(t,e)<=r}function u(t,e){return{x:e.x-t.x,y:e.y-t.y}}function c(t,e){return{x:t.x+e.x,y:t.y+e.y}}var l=r(30);function h(t,e){return(0,l.direction)(u(t,e))}var f=r(986);function d(t){return{x:(0,f.mean)(t.map(function(t){return t.x})),y:(0,f.mean)(t.map(function(t){return t.y}))}}function g(t,e){return d([t,e])}})(),n})()},854(t){t.exports=(()=>{"use strict";var t={d:(e,r)=>{for(var n in r)t.o(r,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:r[n]})},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 n(t){return r(t)&&Number.isFinite(t)}function i(t){return r(t)&&!Number.isFinite(t)}function o(t){return n(t)&&t>0}function a(t){return n(t)&&t>=0}function s(t){return"string"==typeof t}function u(t){return""===t}function c(t){return s(t)&&!u(t)}function l(t){return!!s(t)&&0==t.trim().length}function h(t){if(!s(t))return!1;try{return JSON.parse(t),!0}catch{return!1}}function f(t){try{return JSON.stringify(t),!0}catch{return!1}}function d(t){return!!t}function g(t){return!t}function m(t){return null==t}function p(t){return"object"==typeof t&&null!==t}function y(t){return Array.isArray(t)}function w(t){return y(t)&&0==t.length}function b(t){return y(t)&&t.length>0}function v(t){return y(t)&&t.every(r)}function S(t){return v(t)&&t.length>0}function x(t){return y(t)&&t.every(n)}function N(t){return y(t)&&t.every(i)}function C(t){return y(t)&&t.every(s)}function E(t){return C(t)&&t.length>0}function P(t){return t instanceof SVGGraphicsElement}return t.r(e),t.d(e,{isArray:()=>y,isEmptyArray:()=>w,isEmptyString:()=>u,isFalsy:()=>g,isFiniteNumber:()=>n,isFiniteNumbersArray:()=>x,isJSON:()=>h,isJSONSerializable:()=>f,isNonEmptyArray:()=>b,isNonEmptyNumbersArray:()=>S,isNonEmptyString:()=>c,isNonEmptyStringsArray:()=>E,isNonFiniteNumber:()=>i,isNonFiniteNumbersArray:()=>N,isNonNegativeFiniteNumber:()=>a,isNonNullObject:()=>p,isNullish:()=>m,isNumber:()=>r,isNumbersArray:()=>v,isPositiveFiniteNumber:()=>o,isSVGGraphicsElement:()=>P,isString:()=>s,isStringsArray:()=>C,isTruthy:()=>d,isWhitespace:()=>l}),e})()}};const e={};function r(n){const i=e[n];if(void 0!==i)return i.exports;const o=e[n]={exports:{}};return t[n].call(o.exports,o,o.exports,r),o.exports}r.d=(t,e)=>{for(var n in e)r.o(e,n)&&!r.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},r.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r.r=t=>{Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};let n={};return(()=>{"use strict";r.r(n),r.d(n,{AbstractPath:()=>s,CoordinateSystem:()=>b,HorizontalClientScaling:()=>S,InnerXML:()=>V,OuterXML:()=>A,Path:()=>o,Scaling:()=>v,Texts:()=>e,VerticalClientScaling:()=>x,assignUUID:()=>w,bringToFront:()=>N,drawOnCanvas:()=>D,isSVGGraphicsElement:()=>T,isSVGGraphicsElementsArray:()=>G,sendToBack:()=>C,setAttributes:()=>h});var t;class e{constructor(e){t.set(this,void 0),function(t,e,r,n,i){if("m"===n)throw new TypeError("Private method is not writable");if("a"===n&&!i)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!i:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");"a"===n?i.call(t,r):i?i.value=r:e.set(t,r)}(this,t,e,"f")}toArray(){return Array.from(function(t,e,r,n){if("a"===r&&!n)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!n:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===r?n:"a"===r?n.call(t):n?n.value:e.get(t)}(this,t,"f").querySelectorAll("text")).map(t=>({domNode:t}))}}t=new WeakMap;var i=r(725);class o{constructor(t){this.domNode=t}closestPoint(t){let e=this.domNode.getTotalLength(),r=[];for(let n=0;n<=16;n++){let o=n/16*e;r.push([o,(0,i.distance)(t,this.domNode.getPointAtLength(o))])}r.sort((t,e)=>t[1]-e[1]);let n=r[0],o=n[0]-e/16,a=n[0]+e/16;o=Math.max(0,o),a=Math.min(e,a);for(let e=0;e<20;e++){let e=(a-o)/3;(0,i.distance)(t,this.domNode.getPointAtLength(o))<(0,i.distance)(t,this.domNode.getPointAtLength(a))?a-=e:o+=e}let s=(o+a)/2,u=this.domNode.getPointAtLength(s);return{x:u.x,y:u.y,length:s}}}var a;class s{constructor(t){a.set(this,void 0),function(t,e,r,n,i){if("m"===n)throw new TypeError("Private method is not writable");if("a"===n&&!i)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!i:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");"a"===n?i.call(t,r):i?i.value=r:e.set(t,r)}(this,a,t,"f")}closestPoint(t){return document.body.contains(c)||document.body.append(c),l.setAttribute("d",function(t,e,r,n){if("a"===r&&!n)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!n:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===r?n:"a"===r?n.call(t):n?n.value:e.get(t)}(this,a,"f")),new o(l).closestPoint(t)}}a=new WeakMap;const u=document.createElementNS("http://www.w3.org/2000/svg","svg");u.setAttribute("viewBox","0 0 100 100"),u.setAttribute("width","100"),u.setAttribute("height","100");const c=document.createElement("div");c.append(u),c.style.height="0px",c.style.position="fixed",document.body.append(c);const l=document.createElementNS("http://www.w3.org/2000/svg","path");function h(t,e){for(let[r,n]of Object.entries(e))t.setAttribute(r,n)}l.setAttribute("stroke","black"),l.setAttribute("stroke-width","1"),u.append(l);const f={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};let d;const g=new Uint8Array(16),m=[];for(let t=0;t<256;++t)m.push((t+256).toString(16).slice(1));function p(t,e,r){const n=(t=t||{}).random??t.rng?.()??function(){if(!d){if("undefined"==typeof crypto||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");d=crypto.getRandomValues.bind(crypto)}return d(g)}();if(n.length<16)throw new Error("Random bytes length must be >= 16");if(n[6]=15&n[6]|64,n[8]=63&n[8]|128,e){if((r=r||0)<0||r+16>e.length)throw new RangeError(`UUID byte range ${r}:${r+15} is out of buffer bounds`);for(let t=0;t<16;++t)e[r+t]=n[t];return e}return function(t,e=0){return(m[t[e+0]]+m[t[e+1]]+m[t[e+2]]+m[t[e+3]]+"-"+m[t[e+4]]+m[t[e+5]]+"-"+m[t[e+6]]+m[t[e+7]]+"-"+m[t[e+8]]+m[t[e+9]]+"-"+m[t[e+10]]+m[t[e+11]]+m[t[e+12]]+m[t[e+13]]+m[t[e+14]]+m[t[e+15]]).toLowerCase()}(n)}const y=function(t,e,r){return!f.randomUUID||e||t?p(t,e,r):f.randomUUID()};function w(t){t.id="uuid-"+y()}class b{constructor(t){this.targetSVGDoc=t}get width(){return this.targetSVGDoc.viewBox.baseVal.width}get height(){return this.targetSVGDoc.viewBox.baseVal.height}get minX(){return this.targetSVGDoc.viewBox.baseVal.x}get maxX(){return this.minX+this.width}get minY(){return this.targetSVGDoc.viewBox.baseVal.y}get maxY(){return this.minY+this.height}get horizontalScaling(){return this.targetSVGDoc.width.baseVal.value/this.width}get verticalScaling(){return this.targetSVGDoc.height.baseVal.value/this.height}setScaling(t){this.targetSVGDoc.setAttribute("width",""+t*this.width),this.targetSVGDoc.setAttribute("height",""+t*this.height)}get clientWidth(){return this.targetSVGDoc.getBoundingClientRect().width}get clientHeight(){return this.targetSVGDoc.getBoundingClientRect().height}get horizontalClientScaling(){return this.clientWidth/this.width}get verticalClientScaling(){return this.clientHeight/this.height}get minClientX(){return this.targetSVGDoc.getBoundingClientRect().x}get minClientY(){return this.targetSVGDoc.getBoundingClientRect().y}fromClientX(t){return this.minX+(t-this.minClientX)/this.horizontalClientScaling}fromClientY(t){return this.minY+(t-this.minClientY)/this.verticalClientScaling}fromClientCoordinates(t,e){return[this.fromClientX(t),this.fromClientY(e)]}fromClientPoint(t){return{x:this.fromClientX(t.x),y:this.fromClientY(t.y)}}toClientX(t){return this.minClientX+this.horizontalClientScaling*(t-this.minX)}toClientY(t){return this.minClientY+this.verticalClientScaling*(t-this.minY)}toClientCoordinates(t,e){return[this.toClientX(t),this.toClientY(e)]}toClientPoint(t){return{x:this.toClientX(t.x),y:this.toClientY(t.y)}}}class v{constructor(t){this.targetSVGDoc=t}set(t){let e=this.targetSVGDoc.viewBox.baseVal;this.targetSVGDoc.setAttribute("width",t*e.width+"px"),this.targetSVGDoc.setAttribute("height",t*e.height+"px")}}class S{constructor(t){this.targetSVGDoc=t}get(){let t=this.targetSVGDoc.getBoundingClientRect(),e=this.targetSVGDoc.viewBox.baseVal;return t.width/e.width}}class x{constructor(t){this.targetSVGDoc=t}get(){let t=this.targetSVGDoc.getBoundingClientRect(),e=this.targetSVGDoc.viewBox.baseVal;return t.height/e.height}}function N(t){let e=t.parentNode;e&&e.appendChild(t)}function C(t){let e=t.parentNode;e&&e.prepend(t)}var E,P=function(t,e,r,n){if("a"===r&&!n)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!n:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===r?n:"a"===r?n.call(t):n?n.value:e.get(t)};class V{constructor(t){E.set(this,void 0),function(t,e,r,n,i){if("m"===n)throw new TypeError("Private method is not writable");if("a"===n&&!i)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!i:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");"a"===n?i.call(t,r):i?i.value=r:e.set(t,r)}(this,E,t,"f")}toString(){return P(this,E,"f").innerHTML}set(t){P(this,E,"f").innerHTML=t}}E=new WeakMap;var M,O=function(t,e,r,n){if("a"===r&&!n)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!n:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===r?n:"a"===r?n.call(t):n?n.value:e.get(t)};class A{constructor(t){M.set(this,void 0),function(t,e,r,n,i){if("m"===n)throw new TypeError("Private method is not writable");if("a"===n&&!i)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!i:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");"a"===n?i.call(t,r):i?i.value=r:e.set(t,r)}(this,M,t,"f")}toString(){return O(this,M,"f").outerHTML}set(t){let e=document.createElementNS("http://www.w3.org/2000/svg","svg");if(e.style.height="0px",document.body.append(e),e.innerHTML=t,!e.firstElementChild)throw new Error("Outer XML must encode an SVG element.");if(e.childNodes.length>1)throw new Error("Outer XML cannot encode multiple DOM nodes.");if(e.firstElementChild.tagName.toLowerCase()!=O(this,M,"f").tagName.toLowerCase())throw new Error("Outer XML must specify an SVG element with the same tag name as the target SVG element.");[...O(this,M,"f").attributes].forEach(t=>O(this,M,"f").removeAttribute(t.name)),[...e.firstElementChild.attributes].forEach(t=>O(this,M,"f").setAttribute(t.name,t.value)),O(this,M,"f").innerHTML=e.firstElementChild.innerHTML,e.remove()}}function T(t){return t instanceof SVGGraphicsElement}M=new WeakMap;var j=r(854);function G(t){return(0,j.isArray)(t)&&t.every(T)}async function D(t){let e=document.createElement("canvas");e.style.position="fixed",e.style.display="none",e.style.pointerEvents="none",document.body.append(e),e.width=t.width.baseVal.value,e.height=t.height.baseVal.value;let r=e.getContext("2d");if(!r)throw new Error("Unable to get canvas context.");let n=(new XMLSerializer).serializeToString(t),i=new Image;return i.src="data:image/svg+xml;charset=utf-8,"+encodeURIComponent(n),await i.decode(),r.drawImage(i,0,0,t.width.baseVal.value,t.height.baseVal.value),e.remove(),e.style.position="",e.style.display="",e.style.pointerEvents="",e}})(),n})());
1
+ !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports["draw.svg"]=e():t["draw.svg"]=e()}(this,()=>(()=>{var t={725(t){t.exports=(()=>{var t={986:function(t){t.exports=(()=>{"use strict";var t={d:(e,r)=>{for(var n in r)t.o(r,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:r[n]})},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 n(t){return r(t)/t.length}function i(t){t.sort(function(t,e){return t-e})}t.r(e),t.d(e,{areWithin:()=>m,average:()=>n,degrees:()=>d,isBetweenExclusive:()=>l,isBetweenInclusive:()=>h,max:()=>u,mean:()=>n,median:()=>s,min:()=>c,radians:()=>p,sortNumbers:()=>i,sortNumbersAscending:()=>i,sortNumbersDescending:()=>y,sortedNumbers:()=>a,sortedNumbersAscending:()=>a,sortedNumbersDescending:()=>f,sum:()=>r});var o=function(t,e,r){if(r||2===arguments.length)for(var n,i=0,o=e.length;i<o;i++)!n&&i in e||(n||(n=Array.prototype.slice.call(e,0,i)),n[i]=e[i]);return t.concat(n||Array.prototype.slice.call(e))};function a(t){var e=o([],t,!0);return i(e),e}function s(t){if(0==t.length)return NaN;var e=a(t);if(e.length%2!=0)return e[Math.floor(e.length/2)];var r=e.length/2,i=r-1;return n([e[r],e[i]])}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 u(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 l(t,e,r){return t>e&&t<r}function m(t,e,r){return Math.abs(t-e)<=r}function y(t){i(t),t.reverse()}function f(t){var e=a(t);return e.reverse(),e}function d(t){return t*(180/Math.PI)}function p(t){return t*(Math.PI/180)}return e})()},854:function(t){t.exports=(()=>{"use strict";var t={d:(e,r)=>{for(var n in r)t.o(r,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:r[n]})},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 n(t){return r(t)&&Number.isFinite(t)}function i(t){return r(t)&&!Number.isFinite(t)}function o(t){return n(t)&&t>0}function a(t){return n(t)&&t>=0}function s(t){return"string"==typeof t}function c(t){return null==t}function u(t){return"object"==typeof t&&null!==t}function h(t){return Array.isArray(t)}return t.r(e),t.d(e,{isArray:()=>h,isFiniteNumber:()=>n,isNonFiniteNumber:()=>i,isNonNegativeFiniteNumber:()=>a,isNonNullObject:()=>u,isNullish:()=>c,isNumber:()=>r,isPositiveFiniteNumber:()=>o,isString:()=>s}),e})()},30:function(t){t.exports=(()=>{"use strict";var t={d:(e,r)=>{for(var n in r)t.o(r,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:r[n]})},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 Math.pow(Math.pow(t.x,2)+Math.pow(t.y,2),.5)}function n(t){return Math.atan2(t.y,t.x)}return t.r(e),t.d(e,{direction:()=>n,magnitude:()=>r}),e})()}},e={};function r(n){var i=e[n];if(void 0!==i)return i.exports;var o=e[n]={exports:{}};return t[n].call(o.exports,o,o.exports,r),o.exports}r.d=(t,e)=>{for(var n in e)r.o(e,n)&&!r.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},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 n={};return(()=>{"use strict";r.r(n),r.d(n,{areWithin:()=>s,centroid:()=>y,deepCopy:()=>o,direction:()=>l,displaced:()=>u,displacement:()=>c,distance:()=>a,isFinitePoint:()=>i,isPoint:()=>e,midpoint:()=>f});var t=r(854);function e(e){return(0,t.isNonNullObject)(e)&&(0,t.isNumber)(e.x)&&(0,t.isNumber)(e.y)}function i(r){return e(r)&&(0,t.isFiniteNumber)(r.x)&&(0,t.isFiniteNumber)(r.y)}function o(t){return{x:t.x,y:t.y}}function a(t,e){var r=e.x-t.x,n=e.y-t.y;return Math.pow(Math.pow(r,2)+Math.pow(n,2),.5)}function s(t,e,r){return a(t,e)<=r}function c(t,e){return{x:e.x-t.x,y:e.y-t.y}}function u(t,e){return{x:t.x+e.x,y:t.y+e.y}}var h=r(30);function l(t,e){return(0,h.direction)(c(t,e))}var m=r(986);function y(t){return{x:(0,m.mean)(t.map(function(t){return t.x})),y:(0,m.mean)(t.map(function(t){return t.y}))}}function f(t,e){return y([t,e])}})(),n})()},854(t){t.exports=(()=>{"use strict";var t={d:(e,r)=>{for(var n in r)t.o(r,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:r[n]})},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 n(t){return r(t)&&Number.isFinite(t)}function i(t){return r(t)&&!Number.isFinite(t)}function o(t){return n(t)&&t>0}function a(t){return n(t)&&t>=0}function s(t){return"string"==typeof t}function c(t){return""===t}function u(t){return s(t)&&!c(t)}function h(t){return!!s(t)&&0==t.trim().length}function l(t){if(!s(t))return!1;try{return JSON.parse(t),!0}catch{return!1}}function m(t){try{return JSON.stringify(t),!0}catch{return!1}}function y(t){return!!t}function f(t){return!t}function d(t){return null==t}function p(t){return"object"==typeof t&&null!==t}function g(t){return Array.isArray(t)}function v(t){return g(t)&&0==t.length}function O(t){return g(t)&&t.length>0}function T(t){return g(t)&&t.every(r)}function x(t){return T(t)&&t.length>0}function N(t){return g(t)&&t.every(n)}function E(t){return g(t)&&t.every(i)}function w(t){return g(t)&&t.every(s)}function b(t){return w(t)&&t.length>0}function _(t){return t instanceof SVGGraphicsElement}return t.r(e),t.d(e,{isArray:()=>g,isEmptyArray:()=>v,isEmptyString:()=>c,isFalsy:()=>f,isFiniteNumber:()=>n,isFiniteNumbersArray:()=>N,isJSON:()=>l,isJSONSerializable:()=>m,isNonEmptyArray:()=>O,isNonEmptyNumbersArray:()=>x,isNonEmptyString:()=>u,isNonEmptyStringsArray:()=>b,isNonFiniteNumber:()=>i,isNonFiniteNumbersArray:()=>E,isNonNegativeFiniteNumber:()=>a,isNonNullObject:()=>p,isNullish:()=>d,isNumber:()=>r,isNumbersArray:()=>T,isPositiveFiniteNumber:()=>o,isSVGGraphicsElement:()=>_,isString:()=>s,isStringsArray:()=>w,isTruthy:()=>y,isWhitespace:()=>h}),e})()}};const e={};function r(n){const i=e[n];if(void 0!==i)return i.exports;const o=e[n]={exports:{}};return t[n].call(o.exports,o,o.exports,r),o.exports}r.d=(t,e)=>{for(var n in e)r.o(e,n)&&!r.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},r.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r.r=t=>{Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};let n={};return(()=>{"use strict";r.r(n),r.d(n,{AbstractPath:()=>U,CoordinateSystem:()=>Z,HorizontalClientScaling:()=>$,InnerXML:()=>K,OuterXML:()=>rt,Path:()=>L,Scaling:()=>B,Text:()=>s,Texts:()=>e,VerticalClientScaling:()=>z,assignUUID:()=>Q,bringToFront:()=>W,drawOnCanvas:()=>at,isSVGGraphicsElement:()=>nt,isSVGGraphicsElementsArray:()=>ot,sendToBack:()=>k,setAttributes:()=>Y});var t;class e{constructor(e){t.set(this,void 0),function(t,e,r,n,i){if("m"===n)throw new TypeError("Private method is not writable");if("a"===n&&!i)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!i:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");"a"===n?i.call(t,r):i?i.value=r:e.set(t,r)}(this,t,e,"f")}toArray(){return Array.from(function(t,e,r,n){if("a"===r&&!n)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!n:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===r?n:"a"===r?n.call(t):n?n.value:e.get(t)}(this,t,"f").querySelectorAll("text")).map(t=>({domNode:t}))}}t=new WeakMap;var i,o=function(t,e,r,n){if("a"===r&&!n)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!n:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===r?n:"a"===r?n.call(t):n?n.value:e.get(t)};class a{constructor(t){i.set(this,void 0),function(t,e,r,n,i){if("m"===n)throw new TypeError("Private method is not writable");if("a"===n&&!i)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!i:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");"a"===n?i.call(t,r):i?i.value=r:e.set(t,r)}(this,i,t,"f")}isEmpty(){return 0==o(this,i,"f").numberOfItems}shift(t){for(let e=0;e<o(this,i,"f").numberOfItems;e++)o(this,i,"f").getItem(e).value+=t}}i=new WeakMap;class s{constructor(t){this.domNode=t}shift(t,e){let r=new a(this.domNode.x.baseVal),n=new a(this.domNode.y.baseVal);r.shift(t),n.shift(e),r.isEmpty()&&this.domNode.setAttribute("x",`${t}`),n.isEmpty()&&this.domNode.setAttribute("y",`${e}`),this.domNode.querySelectorAll("tspan").forEach(r=>{new a(r.x.baseVal).shift(t),new a(r.y.baseVal).shift(e)})}}var c=r(725);const u=" ";function h([t,e],r){return[t*Math.cos(r)-e*Math.sin(r),t*Math.sin(r)+e*Math.cos(r)]}function l(...t){for(let e=0;e<t.length;e++)if("number"!=typeof t[e])throw new Error(`assertNumbers arguments[${e}] is not a number. ${typeof t[e]} == typeof ${t[e]}`);return!0}const m=Math.PI;function y(t,e,r){t.lArcFlag=0===t.lArcFlag?0:1,t.sweepFlag=0===t.sweepFlag?0:1;let{rX:n,rY:i}=t;const{x:o,y:a}=t;if(Math.abs(n)<1e-10||Math.abs(i)<1e-10)return t.rX=0,t.rY=0,t.cX=(e+o)/2,t.cY=(r+a)/2,t.phi1=0,void(t.phi2=0);n=Math.abs(t.rX),i=Math.abs(t.rY);const s=t.xRot/180*m,[c,u]=h([(e-o)/2,(r-a)/2],-s),l=Math.pow(c,2)/Math.pow(n,2)+Math.pow(u,2)/Math.pow(i,2);1<l&&(n*=Math.sqrt(l),i*=Math.sqrt(l)),t.rX=n,t.rY=i;const y=Math.pow(n,2)*Math.pow(u,2)+Math.pow(i,2)*Math.pow(c,2),f=(t.lArcFlag!==t.sweepFlag?1:-1)*Math.sqrt(Math.max(0,(Math.pow(n,2)*Math.pow(i,2)-y)/y)),d=n*u/i*f,p=-i*c/n*f,g=h([d,p],s);t.cX=g[0]+(e+o)/2,t.cY=g[1]+(r+a)/2,t.phi1=Math.atan2((u-p)/i,(c-d)/n),t.phi2=Math.atan2((-u-p)/i,(-c-d)/n),0===t.sweepFlag&&t.phi2>t.phi1&&(t.phi2-=2*m),1===t.sweepFlag&&t.phi2<t.phi1&&(t.phi2+=2*m),t.phi1*=180/m,t.phi2*=180/m}function f(t,e,r){l(t,e,r);const n=t*t+e*e-r*r;if(0>n)return[];if(0===n)return[[t*r/(t*t+e*e),e*r/(t*t+e*e)]];const i=Math.sqrt(n);return[[(t*r+e*i)/(t*t+e*e),(e*r-t*i)/(t*t+e*e)],[(t*r-e*i)/(t*t+e*e),(e*r+t*i)/(t*t+e*e)]]}const d=Math.PI/180;function p(t,e,r){return(1-r)*t+r*e}function g(t,e,r,n){return t+Math.cos(n/180*m)*e+Math.sin(n/180*m)*r}function v(t,e,r,n){const i=1e-6,o=e-t,a=r-e,s=3*o+3*(n-r)-6*a,c=6*(a-o),u=3*o;return Math.abs(s)<i?Math.abs(c)<i?[]:[-u/c]:function(t,e,r=1e-6){const n=t*t/4-e;if(n<-r)return[];if(n<=r)return[-t/2];const i=Math.sqrt(n);return[-t/2-i,-t/2+i]}(c/s,u/s,i)}function O(t,e,r,n,i){const o=1-i;return t*(o*o*o)+e*(3*o*o*i)+r*(3*o*i*i)+n*(i*i*i)}function T(t,e,r){const n=e[0]-t[0],i=e[1]-t[1],o=r[0]-t[0],a=r[1]-t[1],s=n*a-i*o;if(!(Math.abs(s)<1e-10))return!1;const c=n*o+i*a,u=o*o+a*a;return 0<=c&&c<=u&&n*n+i*i<=u}function x(t){const e=t[t.length-1]?.type===V.CLOSE_PATH,r=e?t.length-2:t.length-1,n=[{type:V.MOVE_TO,relative:!1,x:t[r].x,y:t[r].y}];for(let e=r;e>0;e--){const r=t[e],i=t[e-1];if(r.relative)throw new Error("Relative command are not supported convert first with `toAbs()`");switch(r.type){case V.HORIZ_LINE_TO:n.push({type:V.HORIZ_LINE_TO,relative:!1,x:i.x});break;case V.VERT_LINE_TO:n.push({type:V.VERT_LINE_TO,relative:!1,y:i.y});break;case V.LINE_TO:case V.MOVE_TO:n.push({type:V.LINE_TO,relative:!1,x:i.x,y:i.y});break;case V.CURVE_TO:n.push({type:V.CURVE_TO,relative:!1,x:i.x,y:i.y,x1:r.x2,y1:r.y2,x2:r.x1,y2:r.y1});break;case V.SMOOTH_CURVE_TO:throw new Error("Unsupported command: S (smooth cubic bezier)");case V.SMOOTH_QUAD_TO:throw new Error("Unsupported command: T (smooth quadratic bezier)");case V.ARC:throw new Error("Unsupported command: A (arc)");case V.QUAD_TO:throw new Error("Unsupported command: Q (quadratic bezier)")}}return e&&n.push({type:V.CLOSE_PATH}),n}function N(){return b((t,e,r)=>(t.relative&&(void 0!==t.x1&&(t.x1+=e),void 0!==t.y1&&(t.y1+=r),void 0!==t.x2&&(t.x2+=e),void 0!==t.y2&&(t.y2+=r),void 0!==t.x&&(t.x+=e),void 0!==t.y&&(t.y+=r),t.relative=!1),t))}function E(){let t=NaN,e=NaN,r=NaN,n=NaN;return b((i,o,a)=>(i.type&V.SMOOTH_CURVE_TO&&(i.type=V.CURVE_TO,t=isNaN(t)?o:t,e=isNaN(e)?a:e,i.x1=i.relative?o-t:2*o-t,i.y1=i.relative?a-e:2*a-e),i.type&V.CURVE_TO?(t=i.relative?o+i.x2:i.x2,e=i.relative?a+i.y2:i.y2):(t=NaN,e=NaN),i.type&V.SMOOTH_QUAD_TO&&(i.type=V.QUAD_TO,r=isNaN(r)?o:r,n=isNaN(n)?a:n,i.x1=i.relative?o-r:2*o-r,i.y1=i.relative?a-n:2*a-n),i.type&V.QUAD_TO?(r=i.relative?o+i.x1:i.x1,n=i.relative?a+i.y1:i.y1):(r=NaN,n=NaN),i))}function w(){let t=NaN,e=NaN;return b((r,n,i)=>{if(r.type&V.SMOOTH_QUAD_TO&&(r.type=V.QUAD_TO,t=isNaN(t)?n:t,e=isNaN(e)?i:e,r.x1=r.relative?n-t:2*n-t,r.y1=r.relative?i-e:2*i-e),r.type&V.QUAD_TO){t=r.relative?n+r.x1:r.x1,e=r.relative?i+r.y1:r.y1;const o=r.x1,a=r.y1;r.type=V.CURVE_TO,r.x1=((r.relative?0:n)+2*o)/3,r.y1=((r.relative?0:i)+2*a)/3,r.x2=(r.x+2*o)/3,r.y2=(r.y+2*a)/3}else t=NaN,e=NaN;return r})}function b(t){let e=0,r=0,n=NaN,i=NaN;return function(o){if(isNaN(n)&&!(o.type&V.MOVE_TO))throw new Error("path must start with moveto");const a=t(o,e,r,n,i);return o.type&V.CLOSE_PATH&&(e=n,r=i),"x"in o&&void 0!==o.x&&(e=o.relative?e+o.x:o.x),"y"in o&&void 0!==o.y&&(r=o.relative?r+o.y:o.y),o.type&V.MOVE_TO&&(n=e,i=r),a}}function _(t,e,r,n,i,o){return l(t,e,r,n,i,o),b((a,s,c,u)=>{const h=a.x1,l=a.x2,m=a.relative&&!isNaN(u),y=void 0!==a.x?a.x:m?0:s,f=void 0!==a.y?a.y:m?0:c;function d(t){return t*t}a.type&V.HORIZ_LINE_TO&&0!==e&&(a.type=V.LINE_TO,a.y=a.relative?0:c),a.type&V.VERT_LINE_TO&&0!==r&&(a.type=V.LINE_TO,a.x=a.relative?0:s),void 0!==a.x&&(a.x=a.x*t+f*r+(m?0:i)),void 0!==a.y&&(a.y=y*e+a.y*n+(m?0:o)),void 0!==a.x1&&(a.x1=a.x1*t+a.y1*r+(m?0:i)),void 0!==a.y1&&(a.y1=h*e+a.y1*n+(m?0:o)),void 0!==a.x2&&(a.x2=a.x2*t+a.y2*r+(m?0:i)),void 0!==a.y2&&(a.y2=l*e+a.y2*n+(m?0:o));const p=t*n-e*r;if(void 0!==a.xRot&&(1!==t||0!==e||0!==r||1!==n))if(0===p)delete a.rX,delete a.rY,delete a.xRot,delete a.lArcFlag,delete a.sweepFlag,a.type=V.LINE_TO;else{const i=a.xRot*Math.PI/180,o=Math.sin(i),s=Math.cos(i),c=1/d(a.rX),u=1/d(a.rY),h=d(s)*c+d(o)*u,l=2*o*s*(c-u),m=d(o)*c+d(s)*u,y=h*n*n-l*e*n+m*e*e,f=l*(t*n+e*r)-2*(h*r*n+m*t*e),g=h*r*r-l*t*r+m*t*t,v=(Math.atan2(f,y-g)+Math.PI)%Math.PI/2,O=Math.sin(v),T=Math.cos(v);a.rX=Math.abs(p)/Math.sqrt(y*d(T)+f*O*T+g*d(O)),a.rY=Math.abs(p)/Math.sqrt(y*d(O)-f*O*T+g*d(T)),a.xRot=180*v/Math.PI}return void 0!==a.sweepFlag&&0>p&&(a.sweepFlag=+!a.sweepFlag),a})}const C={ROUND:function(t=1e13){function e(e){return Math.round(e*t)/t}return l(t),function(t){return"x1"in t&&void 0!==t.x1&&(t.x1=e(t.x1)),"y1"in t&&void 0!==t.y1&&(t.y1=e(t.y1)),"x2"in t&&void 0!==t.x2&&(t.x2=e(t.x2)),"y2"in t&&void 0!==t.y2&&(t.y2=e(t.y2)),"x"in t&&void 0!==t.x&&(t.x=e(t.x)),"y"in t&&void 0!==t.y&&(t.y=e(t.y)),"rX"in t&&void 0!==t.rX&&(t.rX=e(t.rX)),"rY"in t&&void 0!==t.rY&&(t.rY=e(t.rY)),t}},TO_ABS:N,TO_REL:function(){return b((t,e,r)=>(t.relative||(void 0!==t.x1&&(t.x1-=e),void 0!==t.y1&&(t.y1-=r),void 0!==t.x2&&(t.x2-=e),void 0!==t.y2&&(t.y2-=r),void 0!==t.x&&(t.x-=e),void 0!==t.y&&(t.y-=r),t.relative=!0),t))},NORMALIZE_HVZ:function(t=!0,e=!0,r=!0,n=!0){return b((i,o,a,s,c)=>{if(isNaN(s)&&!(i.type&V.MOVE_TO))throw new Error("path must start with moveto");if(e&&i.type&V.HORIZ_LINE_TO&&(i.type=V.LINE_TO,i.y=i.relative?0:a),r&&i.type&V.VERT_LINE_TO&&(i.type=V.LINE_TO,i.x=i.relative?0:o),t&&i.type&V.CLOSE_PATH&&(i.type=V.LINE_TO,i.x=i.relative?s-o:s,i.y=i.relative?c-a:c),i.type&V.ARC&&(0===i.rX||0===i.rY)&&(i.type=V.LINE_TO,delete i.rX,delete i.rY,delete i.xRot,delete i.lArcFlag,delete i.sweepFlag),n&&i.type&V.QUAD_TO&&T([o,a],i.relative?[o+i.x1,a+i.y1]:[i.x1,i.y1],i.relative?[o+i.x,a+i.y]:[i.x,i.y])&&(i.type=V.LINE_TO,delete i.x1,delete i.y1),n&&i.type&V.CURVE_TO){const t=[o,a],e=i.relative?[o+i.x1,a+i.y1]:[i.x1,i.y1],r=i.relative?[o+i.x2,a+i.y2]:[i.x2,i.y2],n=i.relative?[o+i.x,a+i.y]:[i.x,i.y];T(t,e,n)&&T(t,r,n)&&(i.type=V.LINE_TO,delete i.x1,delete i.y1,delete i.x2,delete i.y2)}return i})},NORMALIZE_ST:E,QT_TO_C:w,INFO:b,SANITIZE:function(t=0){l(t);let e=NaN,r=NaN,n=NaN,i=NaN;return b((o,a,s,c,u)=>{const h=Math.abs;let l=!1,m=0,y=0;if(o.type&V.SMOOTH_CURVE_TO&&(m=isNaN(e)?0:a-e,y=isNaN(r)?0:s-r),o.type&(V.CURVE_TO|V.SMOOTH_CURVE_TO)?(e=o.relative?a+o.x2:o.x2,r=o.relative?s+o.y2:o.y2):(e=NaN,r=NaN),o.type&V.SMOOTH_QUAD_TO?(n=isNaN(n)?a:2*a-n,i=isNaN(i)?s:2*s-i):o.type&V.QUAD_TO?(n=o.relative?a+o.x1:o.x1,i=o.relative?s+o.y1:o.y2):(n=NaN,i=NaN),o.type&V.LINE_COMMANDS||o.type&V.ARC&&(0===o.rX||0===o.rY||!o.lArcFlag)||o.type&V.CURVE_TO||o.type&V.SMOOTH_CURVE_TO||o.type&V.QUAD_TO||o.type&V.SMOOTH_QUAD_TO){const e=void 0===o.x?0:o.relative?o.x:o.x-a,r=void 0===o.y?0:o.relative?o.y:o.y-s;m=isNaN(n)?void 0===o.x1?m:o.relative?o.x:o.x1-a:n-a,y=isNaN(i)?void 0===o.y1?y:o.relative?o.y:o.y1-s:i-s;const c=void 0===o.x2?0:o.relative?o.x:o.x2-a,u=void 0===o.y2?0:o.relative?o.y:o.y2-s;h(e)<=t&&h(r)<=t&&h(m)<=t&&h(y)<=t&&h(c)<=t&&h(u)<=t&&(l=!0)}return o.type&V.CLOSE_PATH&&h(a-c)<=t&&h(s-u)<=t&&(l=!0),l?[]:o})},MATRIX:_,ROTATE:function(t,e=0,r=0){l(t,e,r);const n=Math.sin(t),i=Math.cos(t);return _(i,n,-n,i,e-e*i+r*n,r-e*n-r*i)},TRANSLATE:function(t,e=0){return l(t,e),_(1,0,0,1,t,e)},SCALE:function(t,e=t){return l(t,e),_(t,0,0,e,0,0)},SKEW_X:function(t){return l(t),_(1,0,Math.tan(t),1,0,0)},SKEW_Y:function(t){return l(t),_(1,Math.tan(t),0,1,0,0)},X_AXIS_SYMMETRY:function(t=0){return l(t),_(-1,0,0,1,t,0)},Y_AXIS_SYMMETRY:function(t=0){return l(t),_(1,0,0,-1,0,t)},A_TO_C:function(){return b((t,e,r)=>V.ARC===t.type?function(t,e,r){t.cX||y(t,e,r);const n=t.xRot/180*m;if(Math.abs(t.rX)<1e-10||Math.abs(t.rY)<1e-10)return[{relative:t.relative,type:V.CURVE_TO,x1:e+(t.x-e)/3,y1:r+(t.y-r)/3,x2:e+2*(t.x-e)/3,y2:r+2*(t.y-r)/3,x:t.x,y:t.y}];const i=Math.min(t.phi1,t.phi2),o=Math.max(t.phi1,t.phi2)-i,a=Math.ceil(o/90),s=new Array(a);let c=e,u=r;const l=(e,r)=>{const[i,o]=h([e*t.rX,r*t.rY],n);return[t.cX+i,t.cY+o]};for(let e=0;e<a;e++){const r=p(t.phi1,t.phi2,e/a),n=p(t.phi1,t.phi2,(e+1)/a),i=n-r,o=4/3*Math.tan(i*d/4),h=Math.cos(r*d)-o*Math.sin(r*d),m=Math.sin(r*d)+o*Math.cos(r*d),y=Math.cos(n*d),f=Math.sin(n*d),g=y+o*f,v=f-o*y,O=l(h,m),T=l(g,v),x=l(y,f),N={relative:t.relative,type:V.CURVE_TO,x:x[0],y:x[1],x1:O[0],y1:O[1],x2:T[0],y2:T[1]};t.relative&&(N.x1-=c,N.y1-=u,N.x2-=c,N.y2-=u,N.x-=c,N.y-=u),c=x[0],u=x[1],s[e]=N}return s}(t,t.relative?0:e,t.relative?0:r):t)},ANNOTATE_ARCS:function(){return b((t,e,r)=>(t.relative&&(e=0,r=0),V.ARC===t.type&&y(t,e,r),t))},CLONE:function(){return t=>({...t})},CALCULATE_BOUNDS:function(){const t=N(),e=w(),r=E(),n=b((i,o,a)=>{const s=r(e(t((t=>({...t}))(i))));function c(t){t>n.maxX&&(n.maxX=t),t<n.minX&&(n.minX=t)}function u(t){t>n.maxY&&(n.maxY=t),t<n.minY&&(n.minY=t)}if(s.type&V.DRAWING_COMMANDS&&(c(o),u(a)),s.type&V.HORIZ_LINE_TO&&c(s.x),s.type&V.VERT_LINE_TO&&u(s.y),s.type&V.LINE_TO&&(c(s.x),u(s.y)),s.type&V.CURVE_TO){c(s.x),u(s.y);const t=v(o,s.x1,s.x2,s.x);for(const e of t)0<e&&1>e&&c(O(o,s.x1,s.x2,s.x,e));const e=v(a,s.y1,s.y2,s.y);for(const t of e)0<t&&1>t&&u(O(a,s.y1,s.y2,s.y,t))}if(s.type&V.ARC){c(s.x),u(s.y),y(s,o,a);const t=s.xRot/180*Math.PI,e=Math.cos(t)*s.rX,r=Math.sin(t)*s.rX,n=-Math.sin(t)*s.rY,i=Math.cos(t)*s.rY,[h,l]=s.phi1<s.phi2?[s.phi1,s.phi2]:-180>s.phi2?[s.phi2+360,s.phi1+360]:[s.phi2,s.phi1],m=([t,e])=>{const r=180*Math.atan2(e,t)/Math.PI;return r<h?r+360:r},d=f(n,-e,0).map(m);for(const t of d)t>h&&t<l&&c(g(s.cX,e,n,t));const p=f(i,-r,0).map(m);for(const t of p)t>h&&t<l&&u(g(s.cY,r,i,t))}return i});return n.minX=1/0,n.maxX=-1/0,n.minY=1/0,n.maxY=-1/0,n},REVERSE_PATH:function(t,e=!0){if(t.length<2)return t;const r=C.INFO((t,e,r)=>({...t,x:t.x??e,y:t.y??r,relative:t.relative??!1})),n=[];let i=[];for(const o of t){const t=r(o);t.type===V.MOVE_TO&&i.length>0&&(e?n.push(...x(i)):n.unshift(...x(i)),i=[]),i.push(t)}return i.length>0&&(e?n.push(...x(i)):n.unshift(...x(i))),n},REMOVE_COLLINEAR:function(t){if(t.length<=2)return t;const e=[],r=t.map(C.INFO((t,e,r)=>{const n="relative"in t&&t.relative;return["x"in t?t.x+(n?e:0):e,"y"in t?t.y+(n?r:0):r]}));let n=r[0];e.push(t[0]);for(let i=1;i<t.length;i++){const o=t[i],a=t[i+1];if(i<t.length-1&&a&&o.type&V.LINE_COMMANDS&&a.type&V.LINE_COMMANDS){const t=r[i+1];if(T(n,r[i],t)){"relative"in a&&a.relative&&("x"in a&&(a.x=t[0]-n[0]),"y"in a&&(a.y=t[1]-n[1]));continue}}e.push(o),n=r[i]}return e}};class A{round(t){return this.transform(C.ROUND(t))}toAbs(){return this.transform(C.TO_ABS())}toRel(){return this.transform(C.TO_REL())}normalizeHVZ(t,e,r){return this.transform(C.NORMALIZE_HVZ(t,e,r))}normalizeST(){return this.transform(C.NORMALIZE_ST())}qtToC(){return this.transform(C.QT_TO_C())}aToC(){return this.transform(C.A_TO_C())}sanitize(t){return this.transform(C.SANITIZE(t))}translate(t,e){return this.transform(C.TRANSLATE(t,e))}scale(t,e){return this.transform(C.SCALE(t,e))}rotate(t,e,r){return this.transform(C.ROTATE(t,e,r))}matrix(t,e,r,n,i,o){return this.transform(C.MATRIX(t,e,r,n,i,o))}skewX(t){return this.transform(C.SKEW_X(t))}skewY(t){return this.transform(C.SKEW_Y(t))}xSymmetry(t){return this.transform(C.X_AXIS_SYMMETRY(t))}ySymmetry(t){return this.transform(C.Y_AXIS_SYMMETRY(t))}annotateArcs(){return this.transform(C.ANNOTATE_ARCS())}}const M=t=>" "===t||"\t"===t||"\r"===t||"\n"===t,S=t=>"0".charCodeAt(0)<=t.charCodeAt(0)&&t.charCodeAt(0)<="9".charCodeAt(0);class R extends A{curNumber="";curCommandType=-1;curCommandRelative=!1;canParseCommandOrComma=!0;curNumberHasExp=!1;curNumberHasExpDigits=!1;curNumberHasDecimal=!1;curArgs=[];finish(t=[]){if(this.parse(" ",t),0!==this.curArgs.length||!this.canParseCommandOrComma)throw new SyntaxError("Unterminated command at the path end.");return t}parse(t,e=[]){const r=t=>{e.push(t),this.curArgs.length=0,this.canParseCommandOrComma=!0};for(let n=0;n<t.length;n++){const i=t[n],o=!(this.curCommandType!==V.ARC||3!==this.curArgs.length&&4!==this.curArgs.length||1!==this.curNumber.length||"0"!==this.curNumber&&"1"!==this.curNumber),a=S(i)&&("0"===this.curNumber&&"0"===i||o);if(!S(i)||a)if("e"!==i&&"E"!==i)if("-"!==i&&"+"!==i||!this.curNumberHasExp||this.curNumberHasExpDigits)if("."!==i||this.curNumberHasExp||this.curNumberHasDecimal||o){if(this.curNumber&&-1!==this.curCommandType){const t=Number(this.curNumber);if(isNaN(t))throw new SyntaxError(`Invalid number ending at ${n}`);if(this.curCommandType===V.ARC)if(0===this.curArgs.length||1===this.curArgs.length){if(0>t)throw new SyntaxError(`Expected positive number, got "${t}" at index "${n}"`)}else if((3===this.curArgs.length||4===this.curArgs.length)&&"0"!==this.curNumber&&"1"!==this.curNumber)throw new SyntaxError(`Expected a flag, got "${this.curNumber}" at index "${n}"`);this.curArgs.push(t),this.curArgs.length===I[this.curCommandType]&&(V.HORIZ_LINE_TO===this.curCommandType?r({type:V.HORIZ_LINE_TO,relative:this.curCommandRelative,x:t}):V.VERT_LINE_TO===this.curCommandType?r({type:V.VERT_LINE_TO,relative:this.curCommandRelative,y:t}):this.curCommandType===V.MOVE_TO||this.curCommandType===V.LINE_TO||this.curCommandType===V.SMOOTH_QUAD_TO?(r({type:this.curCommandType,relative:this.curCommandRelative,x:this.curArgs[0],y:this.curArgs[1]}),V.MOVE_TO===this.curCommandType&&(this.curCommandType=V.LINE_TO)):this.curCommandType===V.CURVE_TO?r({type:V.CURVE_TO,relative:this.curCommandRelative,x1:this.curArgs[0],y1:this.curArgs[1],x2:this.curArgs[2],y2:this.curArgs[3],x:this.curArgs[4],y:this.curArgs[5]}):this.curCommandType===V.SMOOTH_CURVE_TO?r({type:V.SMOOTH_CURVE_TO,relative:this.curCommandRelative,x2:this.curArgs[0],y2:this.curArgs[1],x:this.curArgs[2],y:this.curArgs[3]}):this.curCommandType===V.QUAD_TO?r({type:V.QUAD_TO,relative:this.curCommandRelative,x1:this.curArgs[0],y1:this.curArgs[1],x:this.curArgs[2],y:this.curArgs[3]}):this.curCommandType===V.ARC&&r({type:V.ARC,relative:this.curCommandRelative,rX:this.curArgs[0],rY:this.curArgs[1],xRot:this.curArgs[2],lArcFlag:this.curArgs[3],sweepFlag:this.curArgs[4],x:this.curArgs[5],y:this.curArgs[6]})),this.curNumber="",this.curNumberHasExpDigits=!1,this.curNumberHasExp=!1,this.curNumberHasDecimal=!1,this.canParseCommandOrComma=!0}if(!M(i))if(","===i&&this.canParseCommandOrComma)this.canParseCommandOrComma=!1;else if("+"!==i&&"-"!==i&&"."!==i)if(a)this.curNumber=i,this.curNumberHasDecimal=!1;else{if(0!==this.curArgs.length)throw new SyntaxError(`Unterminated command at index ${n}.`);if(!this.canParseCommandOrComma)throw new SyntaxError(`Unexpected character "${i}" at index ${n}. Command cannot follow comma`);if(this.canParseCommandOrComma=!1,"z"!==i&&"Z"!==i)if("h"===i||"H"===i)this.curCommandType=V.HORIZ_LINE_TO,this.curCommandRelative="h"===i;else if("v"===i||"V"===i)this.curCommandType=V.VERT_LINE_TO,this.curCommandRelative="v"===i;else if("m"===i||"M"===i)this.curCommandType=V.MOVE_TO,this.curCommandRelative="m"===i;else if("l"===i||"L"===i)this.curCommandType=V.LINE_TO,this.curCommandRelative="l"===i;else if("c"===i||"C"===i)this.curCommandType=V.CURVE_TO,this.curCommandRelative="c"===i;else if("s"===i||"S"===i)this.curCommandType=V.SMOOTH_CURVE_TO,this.curCommandRelative="s"===i;else if("q"===i||"Q"===i)this.curCommandType=V.QUAD_TO,this.curCommandRelative="q"===i;else if("t"===i||"T"===i)this.curCommandType=V.SMOOTH_QUAD_TO,this.curCommandRelative="t"===i;else{if("a"!==i&&"A"!==i)throw new SyntaxError(`Unexpected character "${i}" at index ${n}.`);this.curCommandType=V.ARC,this.curCommandRelative="a"===i}else e.push({type:V.CLOSE_PATH}),this.canParseCommandOrComma=!0,this.curCommandType=-1}else this.curNumber=i,this.curNumberHasDecimal="."===i}else this.curNumber+=i,this.curNumberHasDecimal=!0;else this.curNumber+=i;else this.curNumber+=i,this.curNumberHasExp=!0;else this.curNumber+=i,this.curNumberHasExpDigits=this.curNumberHasExp}return e}transform(t){return Object.create(this,{parse:{value(e,r=[]){const n=Object.getPrototypeOf(this).parse.call(this,e);for(const e of n){const n=t(e);Array.isArray(n)?r.push(...n):r.push(n)}return r}}})}}class V extends A{commands;constructor(t){super(),this.commands="string"==typeof t?V.parse(t):t}encode(){return V.encode(this.commands)}getBounds(){const t=C.CALCULATE_BOUNDS();return this.transform(t),t}transform(t){const e=[];for(const r of this.commands){const n=t(r);Array.isArray(n)?e.push(...n):e.push(n)}return this.commands=e,this}reverse(t=!0){return this.commands=C.REVERSE_PATH(this.commands,t),this}removeCollinear(){return this.commands=C.REMOVE_COLLINEAR(this.commands),this}static encode(t){return function(t){let e="";Array.isArray(t)||(t=[t]);for(let r=0;r<t.length;r++){const n=t[r];if(n.type===V.CLOSE_PATH)e+="z";else if(n.type===V.HORIZ_LINE_TO)e+=(n.relative?"h":"H")+n.x;else if(n.type===V.VERT_LINE_TO)e+=(n.relative?"v":"V")+n.y;else if(n.type===V.MOVE_TO)e+=(n.relative?"m":"M")+n.x+u+n.y;else if(n.type===V.LINE_TO)e+=(n.relative?"l":"L")+n.x+u+n.y;else if(n.type===V.CURVE_TO)e+=(n.relative?"c":"C")+n.x1+u+n.y1+u+n.x2+u+n.y2+u+n.x+u+n.y;else if(n.type===V.SMOOTH_CURVE_TO)e+=(n.relative?"s":"S")+n.x2+u+n.y2+u+n.x+u+n.y;else if(n.type===V.QUAD_TO)e+=(n.relative?"q":"Q")+n.x1+u+n.y1+u+n.x+u+n.y;else if(n.type===V.SMOOTH_QUAD_TO)e+=(n.relative?"t":"T")+n.x+u+n.y;else{if(n.type!==V.ARC)throw new Error(`Unexpected command type "${n?.type}" at index ${r}.`);e+=(n.relative?"a":"A")+n.rX+u+n.rY+u+n.xRot+u+ +n.lArcFlag+u+ +n.sweepFlag+u+n.x+u+n.y}}return e}(t)}static parse(t){const e=new R,r=[];return e.parse(t,r),e.finish(r),r}static CLOSE_PATH=1;static MOVE_TO=2;static HORIZ_LINE_TO=4;static VERT_LINE_TO=8;static LINE_TO=16;static CURVE_TO=32;static SMOOTH_CURVE_TO=64;static QUAD_TO=128;static SMOOTH_QUAD_TO=256;static ARC=512;static LINE_COMMANDS=V.LINE_TO|V.HORIZ_LINE_TO|V.VERT_LINE_TO;static DRAWING_COMMANDS=V.HORIZ_LINE_TO|V.VERT_LINE_TO|V.LINE_TO|V.CURVE_TO|V.SMOOTH_CURVE_TO|V.QUAD_TO|V.SMOOTH_QUAD_TO|V.ARC}const I={[V.MOVE_TO]:2,[V.LINE_TO]:2,[V.HORIZ_LINE_TO]:1,[V.VERT_LINE_TO]:1,[V.CLOSE_PATH]:0,[V.QUAD_TO]:4,[V.SMOOTH_QUAD_TO]:2,[V.CURVE_TO]:6,[V.SMOOTH_CURVE_TO]:4,[V.ARC]:7};class L{constructor(t){this.domNode=t}shift(t,e){var r;let n=null!==(r=this.domNode.getAttribute("d"))&&void 0!==r?r:"";this.domNode.setAttribute("d",new V(n).translate(t,e).encode())}closestPoint(t){let e=this.domNode.getTotalLength(),r=[];for(let n=0;n<=16;n++){let i=n/16*e;r.push([i,(0,c.distance)(t,this.domNode.getPointAtLength(i))])}r.sort((t,e)=>t[1]-e[1]);let n=r[0],i=n[0]-e/16,o=n[0]+e/16;i=Math.max(0,i),o=Math.min(e,o);for(let e=0;e<20;e++){let e=(o-i)/3;(0,c.distance)(t,this.domNode.getPointAtLength(i))<(0,c.distance)(t,this.domNode.getPointAtLength(o))?o-=e:i+=e}let a=(i+o)/2,s=this.domNode.getPointAtLength(a);return{x:s.x,y:s.y,length:a}}}var P;class U{constructor(t){P.set(this,void 0),function(t,e,r,n,i){if("m"===n)throw new TypeError("Private method is not writable");if("a"===n&&!i)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!i:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");"a"===n?i.call(t,r):i?i.value=r:e.set(t,r)}(this,P,t,"f")}closestPoint(t){return document.body.contains(H)||document.body.append(H),X.setAttribute("d",function(t,e,r,n){if("a"===r&&!n)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!n:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===r?n:"a"===r?n.call(t):n?n.value:e.get(t)}(this,P,"f")),new L(X).closestPoint(t)}}P=new WeakMap;const D=document.createElementNS("http://www.w3.org/2000/svg","svg");D.setAttribute("viewBox","0 0 100 100"),D.setAttribute("width","100"),D.setAttribute("height","100");const H=document.createElement("div");H.append(D),H.style.height="0px",H.style.position="fixed",document.body.append(H);const X=document.createElementNS("http://www.w3.org/2000/svg","path");function Y(t,e){for(let[r,n]of Object.entries(e))t.setAttribute(r,n)}X.setAttribute("stroke","black"),X.setAttribute("stroke-width","1"),D.append(X);const j=new Uint8Array(16),F=[];for(let t=0;t<256;++t)F.push((t+256).toString(16).slice(1));const G=function(t,e,r){return e||t||!crypto.randomUUID?function(t,e,r){const n=(t=t||{}).random??t.rng?.()??crypto.getRandomValues(j);if(n.length<16)throw new Error("Random bytes length must be >= 16");if(n[6]=15&n[6]|64,n[8]=63&n[8]|128,e){if((r=r||0)<0||r+16>e.length)throw new RangeError(`UUID byte range ${r}:${r+15} is out of buffer bounds`);for(let t=0;t<16;++t)e[r+t]=n[t];return e}return function(t,e=0){return(F[t[e+0]]+F[t[e+1]]+F[t[e+2]]+F[t[e+3]]+"-"+F[t[e+4]]+F[t[e+5]]+"-"+F[t[e+6]]+F[t[e+7]]+"-"+F[t[e+8]]+F[t[e+9]]+"-"+F[t[e+10]]+F[t[e+11]]+F[t[e+12]]+F[t[e+13]]+F[t[e+14]]+F[t[e+15]]).toLowerCase()}(n)}(t,e,r):crypto.randomUUID()};function Q(t){t.id="uuid-"+G()}class Z{constructor(t){this.targetSVGDoc=t}get width(){return this.targetSVGDoc.viewBox.baseVal.width}get height(){return this.targetSVGDoc.viewBox.baseVal.height}get minX(){return this.targetSVGDoc.viewBox.baseVal.x}get maxX(){return this.minX+this.width}get minY(){return this.targetSVGDoc.viewBox.baseVal.y}get maxY(){return this.minY+this.height}get horizontalScaling(){return this.targetSVGDoc.width.baseVal.value/this.width}get verticalScaling(){return this.targetSVGDoc.height.baseVal.value/this.height}setScaling(t){this.targetSVGDoc.setAttribute("width",""+t*this.width),this.targetSVGDoc.setAttribute("height",""+t*this.height)}get clientWidth(){return this.targetSVGDoc.getBoundingClientRect().width}get clientHeight(){return this.targetSVGDoc.getBoundingClientRect().height}get horizontalClientScaling(){return this.clientWidth/this.width}get verticalClientScaling(){return this.clientHeight/this.height}get minClientX(){return this.targetSVGDoc.getBoundingClientRect().x}get minClientY(){return this.targetSVGDoc.getBoundingClientRect().y}fromClientX(t){return this.minX+(t-this.minClientX)/this.horizontalClientScaling}fromClientY(t){return this.minY+(t-this.minClientY)/this.verticalClientScaling}fromClientCoordinates(t,e){return[this.fromClientX(t),this.fromClientY(e)]}fromClientPoint(t){return{x:this.fromClientX(t.x),y:this.fromClientY(t.y)}}toClientX(t){return this.minClientX+this.horizontalClientScaling*(t-this.minX)}toClientY(t){return this.minClientY+this.verticalClientScaling*(t-this.minY)}toClientCoordinates(t,e){return[this.toClientX(t),this.toClientY(e)]}toClientPoint(t){return{x:this.toClientX(t.x),y:this.toClientY(t.y)}}}class B{constructor(t){this.targetSVGDoc=t}set(t){let e=this.targetSVGDoc.viewBox.baseVal;this.targetSVGDoc.setAttribute("width",t*e.width+"px"),this.targetSVGDoc.setAttribute("height",t*e.height+"px")}}class ${constructor(t){this.targetSVGDoc=t}get(){let t=this.targetSVGDoc.getBoundingClientRect(),e=this.targetSVGDoc.viewBox.baseVal;return t.width/e.width}}class z{constructor(t){this.targetSVGDoc=t}get(){let t=this.targetSVGDoc.getBoundingClientRect(),e=this.targetSVGDoc.viewBox.baseVal;return t.height/e.height}}function W(t){let e=t.parentNode;e&&e.appendChild(t)}function k(t){let e=t.parentNode;e&&e.prepend(t)}var q,J=function(t,e,r,n){if("a"===r&&!n)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!n:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===r?n:"a"===r?n.call(t):n?n.value:e.get(t)};class K{constructor(t){q.set(this,void 0),function(t,e,r,n,i){if("m"===n)throw new TypeError("Private method is not writable");if("a"===n&&!i)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!i:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");"a"===n?i.call(t,r):i?i.value=r:e.set(t,r)}(this,q,t,"f")}toString(){return J(this,q,"f").innerHTML}set(t){J(this,q,"f").innerHTML=t}}q=new WeakMap;var tt,et=function(t,e,r,n){if("a"===r&&!n)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!n:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===r?n:"a"===r?n.call(t):n?n.value:e.get(t)};class rt{constructor(t){tt.set(this,void 0),function(t,e,r,n,i){if("m"===n)throw new TypeError("Private method is not writable");if("a"===n&&!i)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!i:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");"a"===n?i.call(t,r):i?i.value=r:e.set(t,r)}(this,tt,t,"f")}toString(){return et(this,tt,"f").outerHTML}set(t){let e=document.createElementNS("http://www.w3.org/2000/svg","svg");if(e.style.height="0px",document.body.append(e),e.innerHTML=t,!e.firstElementChild)throw new Error("Outer XML must encode an SVG element.");if(e.childNodes.length>1)throw new Error("Outer XML cannot encode multiple DOM nodes.");if(e.firstElementChild.tagName.toLowerCase()!=et(this,tt,"f").tagName.toLowerCase())throw new Error("Outer XML must specify an SVG element with the same tag name as the target SVG element.");[...et(this,tt,"f").attributes].forEach(t=>et(this,tt,"f").removeAttribute(t.name)),[...e.firstElementChild.attributes].forEach(t=>et(this,tt,"f").setAttribute(t.name,t.value)),et(this,tt,"f").innerHTML=e.firstElementChild.innerHTML,e.remove()}}function nt(t){return t instanceof SVGGraphicsElement}tt=new WeakMap;var it=r(854);function ot(t){return(0,it.isArray)(t)&&t.every(nt)}async function at(t){let e=document.createElement("canvas");e.style.position="fixed",e.style.display="none",e.style.pointerEvents="none",document.body.append(e),e.width=t.width.baseVal.value,e.height=t.height.baseVal.value;let r=e.getContext("2d");if(!r)throw new Error("Unable to get canvas context.");let n=(new XMLSerializer).serializeToString(t),i=new Image;return i.src="data:image/svg+xml;charset=utf-8,"+encodeURIComponent(n),await i.decode(),r.drawImage(i,0,0,t.width.baseVal.value,t.height.baseVal.value),e.remove(),e.style.position="",e.style.display="",e.style.pointerEvents="",e}})(),n})());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rnacanvas/draw.svg",
3
- "version": "4.1.0",
3
+ "version": "4.3.0",
4
4
  "description": "SVG drawing utilities",
5
5
  "repository": {
6
6
  "type": "git",
@@ -14,9 +14,9 @@
14
14
  "author": "pzhaojohnson",
15
15
  "license": "MIT",
16
16
  "devDependencies": {
17
- "@babel/core": "^7.23.7",
18
- "@babel/preset-env": "^7.23.7",
19
- "@babel/preset-typescript": "^7.23.3",
17
+ "@babel/core": "^8.1.0",
18
+ "@babel/preset-env": "^8.0.7",
19
+ "@babel/preset-typescript": "^8.0.7",
20
20
  "@types/uuid": "^10.0.0",
21
21
  "babel-jest": "^30.1.2",
22
22
  "canvas": "^3.2.0",
@@ -31,6 +31,7 @@
31
31
  "@rnacanvas/points": "^1.12.0",
32
32
  "@rnacanvas/value-check": "^2.7.0",
33
33
  "@svgdotjs/svg.js": "^3.2.0",
34
- "uuid": "^13.0.2"
34
+ "svg-pathdata": "^9.0.0",
35
+ "uuid": "^14.0.3"
35
36
  }
36
37
  }