@rnacanvas/draw.svg 4.0.0 → 4.2.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 +48 -0
- package/dist/Path.d.ts +6 -0
- package/dist/Path.d.ts.map +1 -1
- package/dist/Texts.d.ts +11 -0
- package/dist/Texts.d.ts.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/package.json +6 -5
package/README.md
CHANGED
|
@@ -17,6 +17,40 @@ import { bringToFront, sendToBack } from '@rnacanvas/draw.svg';
|
|
|
17
17
|
import { InnerXML, OuterXML } from '@rnacanvas/draw.svg';
|
|
18
18
|
```
|
|
19
19
|
|
|
20
|
+
## `class Texts`
|
|
21
|
+
|
|
22
|
+
Represents all text elements in a target SVG document.
|
|
23
|
+
|
|
24
|
+
```javascript
|
|
25
|
+
var targetSVG = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
|
|
26
|
+
|
|
27
|
+
var texts = new Texts(targetSVG);
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### `toArray()`
|
|
31
|
+
|
|
32
|
+
Returns all text elements in the target SVG document (including nested ones) as an array
|
|
33
|
+
in document order.
|
|
34
|
+
|
|
35
|
+
Each text element is wrapped in an object
|
|
36
|
+
with a reference to the text element DOM node stored within the `domNode` property.
|
|
37
|
+
|
|
38
|
+
```javascript
|
|
39
|
+
var text1 = document.createElementNS('http://www.w3.org/2000/svg', 'text');
|
|
40
|
+
var text2 = document.createElementNS('http://www.w3.org/2000/svg', 'text');
|
|
41
|
+
|
|
42
|
+
targetSVG.append(text1);
|
|
43
|
+
|
|
44
|
+
var g = document.createElementNS('http://www.w3.org/2000/svg', 'g');
|
|
45
|
+
g.append(text2);
|
|
46
|
+
targetSVG.append(g);
|
|
47
|
+
|
|
48
|
+
texts.toArray().length; // 2
|
|
49
|
+
|
|
50
|
+
texts.toArray()[0].domNode === text1; // true
|
|
51
|
+
texts.toArray()[1].domNode === text2; // true
|
|
52
|
+
```
|
|
53
|
+
|
|
20
54
|
## `class Path`
|
|
21
55
|
|
|
22
56
|
Wraps an SVG path element.
|
|
@@ -33,6 +67,20 @@ var path = new Path(domNode);
|
|
|
33
67
|
path.domNode === domNode; // true
|
|
34
68
|
```
|
|
35
69
|
|
|
70
|
+
### `shift()`
|
|
71
|
+
|
|
72
|
+
Shifts the path by the specified vector.
|
|
73
|
+
|
|
74
|
+
(Modifies the `d` attribute directly rather than the `transform` attribute, for instance.)
|
|
75
|
+
|
|
76
|
+
```javascript
|
|
77
|
+
path.domNode.setAttribute('d', 'M 0 0 L 10 10');
|
|
78
|
+
|
|
79
|
+
path.shift(5, -5);
|
|
80
|
+
|
|
81
|
+
path.domNode.getAttribute('d'); // 'M5 -5L15 5'
|
|
82
|
+
```
|
|
83
|
+
|
|
36
84
|
### `closestPoint()`
|
|
37
85
|
|
|
38
86
|
Calculates and returns the closest point along the path to a given point
|
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).
|
package/dist/Path.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Path.d.ts","sourceRoot":"","sources":["../src/Path.ts"],"names":[],"mappings":"
|
|
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/Texts.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Texts.d.ts","sourceRoot":"","sources":["../src/Texts.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,KAAK;;gBAGJ,SAAS,EAAE,aAAa;IAIpC,OAAO;;;CAGR"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,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,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 b(t){return y(t)&&0==t.length}function w(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 N(t){return y(t)&&t.every(n)}function x(t){return y(t)&&t.every(i)}function C(t){return y(t)&&t.every(s)}function P(t){return C(t)&&t.length>0}function E(t){return t instanceof SVGGraphicsElement}return t.r(e),t.d(e,{isArray:()=>y,isEmptyArray:()=>b,isEmptyString:()=>u,isFalsy:()=>g,isFiniteNumber:()=>n,isFiniteNumbersArray:()=>N,isJSON:()=>h,isJSONSerializable:()=>f,isNonEmptyArray:()=>w,isNonEmptyNumbersArray:()=>S,isNonEmptyString:()=>c,isNonEmptyStringsArray:()=>P,isNonFiniteNumber:()=>i,isNonFiniteNumbersArray:()=>x,isNonNegativeFiniteNumber:()=>a,isNonNullObject:()=>p,isNullish:()=>m,isNumber:()=>r,isNumbersArray:()=>v,isPositiveFiniteNumber:()=>o,isSVGGraphicsElement:()=>E,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)=>{if(Array.isArray(e))for(var n=0;n<e.length;){var i=e[n++],o=e[n++];r.o(t,i)?0===o&&n++:0===o?Object.defineProperty(t,i,{enumerable:!0,value:e[n++]}):Object.defineProperty(t,i,{enumerable:!0,get:o})}else 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=>{Symbol.toStringTag&&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:()=>o,CoordinateSystem:()=>y,HorizontalClientScaling:()=>w,InnerXML:()=>P,OuterXML:()=>O,Path:()=>e,Scaling:()=>b,VerticalClientScaling:()=>v,assignUUID:()=>p,bringToFront:()=>S,drawOnCanvas:()=>T,isSVGGraphicsElement:()=>M,isSVGGraphicsElementsArray:()=>A,sendToBack:()=>N,setAttributes:()=>c});var t=r(725);class e{constructor(t){this.domNode=t}closestPoint(e){let r=this.domNode.getTotalLength(),n=[];for(let i=0;i<=16;i++){let o=i/16*r;n.push([o,(0,t.distance)(e,this.domNode.getPointAtLength(o))])}n.sort((t,e)=>t[1]-e[1]);let i=n[0],o=i[0]-r/16,a=i[0]+r/16;o=Math.max(0,o),a=Math.min(r,a);for(let r=0;r<20;r++){let r=(a-o)/3;(0,t.distance)(e,this.domNode.getPointAtLength(o))<(0,t.distance)(e,this.domNode.getPointAtLength(a))?a-=r:o+=r}let s=(o+a)/2,u=this.domNode.getPointAtLength(s);return{x:u.x,y:u.y,length:s}}}var i;class o{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")}closestPoint(t){return document.body.contains(s)||document.body.append(s),u.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,i,"f")),new e(u).closestPoint(t)}}i=new WeakMap;const a=document.createElementNS("http://www.w3.org/2000/svg","svg");a.setAttribute("viewBox","0 0 100 100"),a.setAttribute("width","100"),a.setAttribute("height","100");const s=document.createElement("div");s.append(a),s.style.height="0px",s.style.position="fixed",document.body.append(s);const u=document.createElementNS("http://www.w3.org/2000/svg","path");function c(t,e){for(let[r,n]of Object.entries(e))t.setAttribute(r,n)}u.setAttribute("stroke","black"),u.setAttribute("stroke-width","1"),a.append(u);const l={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};let h;const f=new Uint8Array(16),d=[];for(let t=0;t<256;++t)d.push((t+256).toString(16).slice(1));function g(t,e,r){const n=(t=t||{}).random??t.rng?.()??function(){if(!h){if("undefined"==typeof crypto||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");h=crypto.getRandomValues.bind(crypto)}return h(f)}();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(d[t[e+0]]+d[t[e+1]]+d[t[e+2]]+d[t[e+3]]+"-"+d[t[e+4]]+d[t[e+5]]+"-"+d[t[e+6]]+d[t[e+7]]+"-"+d[t[e+8]]+d[t[e+9]]+"-"+d[t[e+10]]+d[t[e+11]]+d[t[e+12]]+d[t[e+13]]+d[t[e+14]]+d[t[e+15]]).toLowerCase()}(n)}const m=function(t,e,r){return!l.randomUUID||e||t?g(t,e,r):l.randomUUID()};function p(t){t.id="uuid-"+m()}class y{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 w{constructor(t){this.targetSVGDoc=t}get(){let t=this.targetSVGDoc.getBoundingClientRect(),e=this.targetSVGDoc.viewBox.baseVal;return t.width/e.width}}class v{constructor(t){this.targetSVGDoc=t}get(){let t=this.targetSVGDoc.getBoundingClientRect(),e=this.targetSVGDoc.viewBox.baseVal;return t.height/e.height}}function S(t){let e=t.parentNode;e&&e.appendChild(t)}function N(t){let e=t.parentNode;e&&e.prepend(t)}var x,C=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 P{constructor(t){x.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,x,t,"f")}toString(){return C(this,x,"f").innerHTML}set(t){C(this,x,"f").innerHTML=t}}x=new WeakMap;var E,V=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 O{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 V(this,E,"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()!=V(this,E,"f").tagName.toLowerCase())throw new Error("Outer XML must specify an SVG element with the same tag name as the target SVG element.");[...V(this,E,"f").attributes].forEach(t=>V(this,E,"f").removeAttribute(t.name)),[...e.firstElementChild.attributes].forEach(t=>V(this,E,"f").setAttribute(t.name,t.value)),V(this,E,"f").innerHTML=e.firstElementChild.innerHTML,e.remove()}}function M(t){return t instanceof SVGGraphicsElement}E=new WeakMap;var j=r(854);function A(t){return(0,j.isArray)(t)&&t.every(M)}async function T(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:()=>f,isBetweenExclusive:()=>l,isBetweenInclusive:()=>h,max:()=>c,mean:()=>n,median:()=>s,min:()=>u,radians:()=>p,sortNumbers:()=>i,sortNumbersAscending:()=>i,sortNumbersDescending:()=>y,sortedNumbers:()=>a,sortedNumbersAscending:()=>a,sortedNumbersDescending:()=>d,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 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 d(t){var e=a(t);return e.reverse(),e}function f(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 h(t){return Array.isArray(t)}return t.r(e),t.d(e,{isArray:()=>h,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:()=>y,deepCopy:()=>o,direction:()=>l,displaced:()=>c,displacement:()=>u,distance:()=>a,isFinitePoint:()=>i,isPoint:()=>e,midpoint:()=>d});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 h=r(30);function l(t,e){return(0,h.direction)(u(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 d(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 u(t){return""===t}function c(t){return s(t)&&!u(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 d(t){return!t}function f(t){return null==t}function p(t){return"object"==typeof t&&null!==t}function g(t){return Array.isArray(t)}function O(t){return g(t)&&0==t.length}function v(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 _(t){return g(t)&&t.every(s)}function w(t){return _(t)&&t.length>0}function b(t){return t instanceof SVGGraphicsElement}return t.r(e),t.d(e,{isArray:()=>g,isEmptyArray:()=>O,isEmptyString:()=>u,isFalsy:()=>d,isFiniteNumber:()=>n,isFiniteNumbersArray:()=>N,isJSON:()=>l,isJSONSerializable:()=>m,isNonEmptyArray:()=>v,isNonEmptyNumbersArray:()=>x,isNonEmptyString:()=>c,isNonEmptyStringsArray:()=>w,isNonFiniteNumber:()=>i,isNonFiniteNumbersArray:()=>E,isNonNegativeFiniteNumber:()=>a,isNonNullObject:()=>p,isNullish:()=>f,isNumber:()=>r,isNumbersArray:()=>T,isPositiveFiniteNumber:()=>o,isSVGGraphicsElement:()=>b,isString:()=>s,isStringsArray:()=>_,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:()=>V,CoordinateSystem:()=>j,HorizontalClientScaling:()=>G,InnerXML:()=>W,OuterXML:()=>J,Path:()=>S,Scaling:()=>F,Texts:()=>e,VerticalClientScaling:()=>Q,assignUUID:()=>Y,bringToFront:()=>Z,drawOnCanvas:()=>rt,isSVGGraphicsElement:()=>K,isSVGGraphicsElementsArray:()=>et,sendToBack:()=>B,setAttributes:()=>U});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);const o=" ";function a([t,e],r){return[t*Math.cos(r)-e*Math.sin(r),t*Math.sin(r)+e*Math.cos(r)]}function s(...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 u=Math.PI;function c(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:s}=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+s)/2,t.phi1=0,void(t.phi2=0);n=Math.abs(t.rX),i=Math.abs(t.rY);const c=t.xRot/180*u,[h,l]=a([(e-o)/2,(r-s)/2],-c),m=Math.pow(h,2)/Math.pow(n,2)+Math.pow(l,2)/Math.pow(i,2);1<m&&(n*=Math.sqrt(m),i*=Math.sqrt(m)),t.rX=n,t.rY=i;const y=Math.pow(n,2)*Math.pow(l,2)+Math.pow(i,2)*Math.pow(h,2),d=(t.lArcFlag!==t.sweepFlag?1:-1)*Math.sqrt(Math.max(0,(Math.pow(n,2)*Math.pow(i,2)-y)/y)),f=n*l/i*d,p=-i*h/n*d,g=a([f,p],c);t.cX=g[0]+(e+o)/2,t.cY=g[1]+(r+s)/2,t.phi1=Math.atan2((l-p)/i,(h-f)/n),t.phi2=Math.atan2((-l-p)/i,(-h-f)/n),0===t.sweepFlag&&t.phi2>t.phi1&&(t.phi2-=2*u),1===t.sweepFlag&&t.phi2<t.phi1&&(t.phi2+=2*u),t.phi1*=180/u,t.phi2*=180/u}function h(t,e,r){s(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 l=Math.PI/180;function m(t,e,r){return(1-r)*t+r*e}function y(t,e,r,n){return t+Math.cos(n/180*u)*e+Math.sin(n/180*u)*r}function d(t,e,r,n){const i=1e-6,o=e-t,a=r-e,s=3*o+3*(n-r)-6*a,u=6*(a-o),c=3*o;return Math.abs(s)<i?Math.abs(u)<i?[]:[-c/u]: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]}(u/s,c/s,i)}function f(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 p(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 u=n*o+i*a,c=o*o+a*a;return 0<=u&&u<=c&&n*n+i*i<=c}function g(t){const e=t[t.length-1]?.type===A.CLOSE_PATH,r=e?t.length-2:t.length-1,n=[{type:A.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 A.HORIZ_LINE_TO:n.push({type:A.HORIZ_LINE_TO,relative:!1,x:i.x});break;case A.VERT_LINE_TO:n.push({type:A.VERT_LINE_TO,relative:!1,y:i.y});break;case A.LINE_TO:case A.MOVE_TO:n.push({type:A.LINE_TO,relative:!1,x:i.x,y:i.y});break;case A.CURVE_TO:n.push({type:A.CURVE_TO,relative:!1,x:i.x,y:i.y,x1:r.x2,y1:r.y2,x2:r.x1,y2:r.y1});break;case A.SMOOTH_CURVE_TO:throw new Error("Unsupported command: S (smooth cubic bezier)");case A.SMOOTH_QUAD_TO:throw new Error("Unsupported command: T (smooth quadratic bezier)");case A.ARC:throw new Error("Unsupported command: A (arc)");case A.QUAD_TO:throw new Error("Unsupported command: Q (quadratic bezier)")}}return e&&n.push({type:A.CLOSE_PATH}),n}function O(){return x((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 v(){let t=NaN,e=NaN,r=NaN,n=NaN;return x((i,o,a)=>(i.type&A.SMOOTH_CURVE_TO&&(i.type=A.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&A.CURVE_TO?(t=i.relative?o+i.x2:i.x2,e=i.relative?a+i.y2:i.y2):(t=NaN,e=NaN),i.type&A.SMOOTH_QUAD_TO&&(i.type=A.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&A.QUAD_TO?(r=i.relative?o+i.x1:i.x1,n=i.relative?a+i.y1:i.y1):(r=NaN,n=NaN),i))}function T(){let t=NaN,e=NaN;return x((r,n,i)=>{if(r.type&A.SMOOTH_QUAD_TO&&(r.type=A.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&A.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=A.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 x(t){let e=0,r=0,n=NaN,i=NaN;return function(o){if(isNaN(n)&&!(o.type&A.MOVE_TO))throw new Error("path must start with moveto");const a=t(o,e,r,n,i);return o.type&A.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&A.MOVE_TO&&(n=e,i=r),a}}function N(t,e,r,n,i,o){return s(t,e,r,n,i,o),x((a,s,u,c)=>{const h=a.x1,l=a.x2,m=a.relative&&!isNaN(c),y=void 0!==a.x?a.x:m?0:s,d=void 0!==a.y?a.y:m?0:u;function f(t){return t*t}a.type&A.HORIZ_LINE_TO&&0!==e&&(a.type=A.LINE_TO,a.y=a.relative?0:u),a.type&A.VERT_LINE_TO&&0!==r&&(a.type=A.LINE_TO,a.x=a.relative?0:s),void 0!==a.x&&(a.x=a.x*t+d*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=A.LINE_TO;else{const i=a.xRot*Math.PI/180,o=Math.sin(i),s=Math.cos(i),u=1/f(a.rX),c=1/f(a.rY),h=f(s)*u+f(o)*c,l=2*o*s*(u-c),m=f(o)*u+f(s)*c,y=h*n*n-l*e*n+m*e*e,d=l*(t*n+e*r)-2*(h*r*n+m*t*e),g=h*r*r-l*t*r+m*t*t,O=(Math.atan2(d,y-g)+Math.PI)%Math.PI/2,v=Math.sin(O),T=Math.cos(O);a.rX=Math.abs(p)/Math.sqrt(y*f(T)+d*v*T+g*f(v)),a.rY=Math.abs(p)/Math.sqrt(y*f(v)-d*v*T+g*f(T)),a.xRot=180*O/Math.PI}return void 0!==a.sweepFlag&&0>p&&(a.sweepFlag=+!a.sweepFlag),a})}const E={ROUND:function(t=1e13){function e(e){return Math.round(e*t)/t}return s(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:O,TO_REL:function(){return x((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 x((i,o,a,s,u)=>{if(isNaN(s)&&!(i.type&A.MOVE_TO))throw new Error("path must start with moveto");if(e&&i.type&A.HORIZ_LINE_TO&&(i.type=A.LINE_TO,i.y=i.relative?0:a),r&&i.type&A.VERT_LINE_TO&&(i.type=A.LINE_TO,i.x=i.relative?0:o),t&&i.type&A.CLOSE_PATH&&(i.type=A.LINE_TO,i.x=i.relative?s-o:s,i.y=i.relative?u-a:u),i.type&A.ARC&&(0===i.rX||0===i.rY)&&(i.type=A.LINE_TO,delete i.rX,delete i.rY,delete i.xRot,delete i.lArcFlag,delete i.sweepFlag),n&&i.type&A.QUAD_TO&&p([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=A.LINE_TO,delete i.x1,delete i.y1),n&&i.type&A.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];p(t,e,n)&&p(t,r,n)&&(i.type=A.LINE_TO,delete i.x1,delete i.y1,delete i.x2,delete i.y2)}return i})},NORMALIZE_ST:v,QT_TO_C:T,INFO:x,SANITIZE:function(t=0){s(t);let e=NaN,r=NaN,n=NaN,i=NaN;return x((o,a,s,u,c)=>{const h=Math.abs;let l=!1,m=0,y=0;if(o.type&A.SMOOTH_CURVE_TO&&(m=isNaN(e)?0:a-e,y=isNaN(r)?0:s-r),o.type&(A.CURVE_TO|A.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&A.SMOOTH_QUAD_TO?(n=isNaN(n)?a:2*a-n,i=isNaN(i)?s:2*s-i):o.type&A.QUAD_TO?(n=o.relative?a+o.x1:o.x1,i=o.relative?s+o.y1:o.y2):(n=NaN,i=NaN),o.type&A.LINE_COMMANDS||o.type&A.ARC&&(0===o.rX||0===o.rY||!o.lArcFlag)||o.type&A.CURVE_TO||o.type&A.SMOOTH_CURVE_TO||o.type&A.QUAD_TO||o.type&A.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 u=void 0===o.x2?0:o.relative?o.x:o.x2-a,c=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(u)<=t&&h(c)<=t&&(l=!0)}return o.type&A.CLOSE_PATH&&h(a-u)<=t&&h(s-c)<=t&&(l=!0),l?[]:o})},MATRIX:N,ROTATE:function(t,e=0,r=0){s(t,e,r);const n=Math.sin(t),i=Math.cos(t);return N(i,n,-n,i,e-e*i+r*n,r-e*n-r*i)},TRANSLATE:function(t,e=0){return s(t,e),N(1,0,0,1,t,e)},SCALE:function(t,e=t){return s(t,e),N(t,0,0,e,0,0)},SKEW_X:function(t){return s(t),N(1,0,Math.tan(t),1,0,0)},SKEW_Y:function(t){return s(t),N(1,Math.tan(t),0,1,0,0)},X_AXIS_SYMMETRY:function(t=0){return s(t),N(-1,0,0,1,t,0)},Y_AXIS_SYMMETRY:function(t=0){return s(t),N(1,0,0,-1,0,t)},A_TO_C:function(){return x((t,e,r)=>A.ARC===t.type?function(t,e,r){t.cX||c(t,e,r);const n=t.xRot/180*u;if(Math.abs(t.rX)<1e-10||Math.abs(t.rY)<1e-10)return[{relative:t.relative,type:A.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,s=Math.ceil(o/90),h=new Array(s);let y=e,d=r;const f=(e,r)=>{const[i,o]=a([e*t.rX,r*t.rY],n);return[t.cX+i,t.cY+o]};for(let e=0;e<s;e++){const r=m(t.phi1,t.phi2,e/s),n=m(t.phi1,t.phi2,(e+1)/s),i=n-r,o=4/3*Math.tan(i*l/4),a=Math.cos(r*l)-o*Math.sin(r*l),u=Math.sin(r*l)+o*Math.cos(r*l),c=Math.cos(n*l),p=Math.sin(n*l),g=c+o*p,O=p-o*c,v=f(a,u),T=f(g,O),x=f(c,p),N={relative:t.relative,type:A.CURVE_TO,x:x[0],y:x[1],x1:v[0],y1:v[1],x2:T[0],y2:T[1]};t.relative&&(N.x1-=y,N.y1-=d,N.x2-=y,N.y2-=d,N.x-=y,N.y-=d),y=x[0],d=x[1],h[e]=N}return h}(t,t.relative?0:e,t.relative?0:r):t)},ANNOTATE_ARCS:function(){return x((t,e,r)=>(t.relative&&(e=0,r=0),A.ARC===t.type&&c(t,e,r),t))},CLONE:function(){return t=>({...t})},CALCULATE_BOUNDS:function(){const t=O(),e=T(),r=v(),n=x((i,o,a)=>{const s=r(e(t((t=>({...t}))(i))));function u(t){t>n.maxX&&(n.maxX=t),t<n.minX&&(n.minX=t)}function l(t){t>n.maxY&&(n.maxY=t),t<n.minY&&(n.minY=t)}if(s.type&A.DRAWING_COMMANDS&&(u(o),l(a)),s.type&A.HORIZ_LINE_TO&&u(s.x),s.type&A.VERT_LINE_TO&&l(s.y),s.type&A.LINE_TO&&(u(s.x),l(s.y)),s.type&A.CURVE_TO){u(s.x),l(s.y);const t=d(o,s.x1,s.x2,s.x);for(const e of t)0<e&&1>e&&u(f(o,s.x1,s.x2,s.x,e));const e=d(a,s.y1,s.y2,s.y);for(const t of e)0<t&&1>t&&l(f(a,s.y1,s.y2,s.y,t))}if(s.type&A.ARC){u(s.x),l(s.y),c(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,[m,d]=s.phi1<s.phi2?[s.phi1,s.phi2]:-180>s.phi2?[s.phi2+360,s.phi1+360]:[s.phi2,s.phi1],f=([t,e])=>{const r=180*Math.atan2(e,t)/Math.PI;return r<m?r+360:r},p=h(n,-e,0).map(f);for(const t of p)t>m&&t<d&&u(y(s.cX,e,n,t));const g=h(i,-r,0).map(f);for(const t of g)t>m&&t<d&&l(y(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=E.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===A.MOVE_TO&&i.length>0&&(e?n.push(...g(i)):n.unshift(...g(i)),i=[]),i.push(t)}return i.length>0&&(e?n.push(...g(i)):n.unshift(...g(i))),n},REMOVE_COLLINEAR:function(t){if(t.length<=2)return t;const e=[],r=t.map(E.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&A.LINE_COMMANDS&&a.type&A.LINE_COMMANDS){const t=r[i+1];if(p(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 _{round(t){return this.transform(E.ROUND(t))}toAbs(){return this.transform(E.TO_ABS())}toRel(){return this.transform(E.TO_REL())}normalizeHVZ(t,e,r){return this.transform(E.NORMALIZE_HVZ(t,e,r))}normalizeST(){return this.transform(E.NORMALIZE_ST())}qtToC(){return this.transform(E.QT_TO_C())}aToC(){return this.transform(E.A_TO_C())}sanitize(t){return this.transform(E.SANITIZE(t))}translate(t,e){return this.transform(E.TRANSLATE(t,e))}scale(t,e){return this.transform(E.SCALE(t,e))}rotate(t,e,r){return this.transform(E.ROTATE(t,e,r))}matrix(t,e,r,n,i,o){return this.transform(E.MATRIX(t,e,r,n,i,o))}skewX(t){return this.transform(E.SKEW_X(t))}skewY(t){return this.transform(E.SKEW_Y(t))}xSymmetry(t){return this.transform(E.X_AXIS_SYMMETRY(t))}ySymmetry(t){return this.transform(E.Y_AXIS_SYMMETRY(t))}annotateArcs(){return this.transform(E.ANNOTATE_ARCS())}}const w=t=>" "===t||"\t"===t||"\r"===t||"\n"===t,b=t=>"0".charCodeAt(0)<=t.charCodeAt(0)&&t.charCodeAt(0)<="9".charCodeAt(0);class C extends _{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!==A.ARC||3!==this.curArgs.length&&4!==this.curArgs.length||1!==this.curNumber.length||"0"!==this.curNumber&&"1"!==this.curNumber),a=b(i)&&("0"===this.curNumber&&"0"===i||o);if(!b(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===A.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===M[this.curCommandType]&&(A.HORIZ_LINE_TO===this.curCommandType?r({type:A.HORIZ_LINE_TO,relative:this.curCommandRelative,x:t}):A.VERT_LINE_TO===this.curCommandType?r({type:A.VERT_LINE_TO,relative:this.curCommandRelative,y:t}):this.curCommandType===A.MOVE_TO||this.curCommandType===A.LINE_TO||this.curCommandType===A.SMOOTH_QUAD_TO?(r({type:this.curCommandType,relative:this.curCommandRelative,x:this.curArgs[0],y:this.curArgs[1]}),A.MOVE_TO===this.curCommandType&&(this.curCommandType=A.LINE_TO)):this.curCommandType===A.CURVE_TO?r({type:A.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===A.SMOOTH_CURVE_TO?r({type:A.SMOOTH_CURVE_TO,relative:this.curCommandRelative,x2:this.curArgs[0],y2:this.curArgs[1],x:this.curArgs[2],y:this.curArgs[3]}):this.curCommandType===A.QUAD_TO?r({type:A.QUAD_TO,relative:this.curCommandRelative,x1:this.curArgs[0],y1:this.curArgs[1],x:this.curArgs[2],y:this.curArgs[3]}):this.curCommandType===A.ARC&&r({type:A.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(!w(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=A.HORIZ_LINE_TO,this.curCommandRelative="h"===i;else if("v"===i||"V"===i)this.curCommandType=A.VERT_LINE_TO,this.curCommandRelative="v"===i;else if("m"===i||"M"===i)this.curCommandType=A.MOVE_TO,this.curCommandRelative="m"===i;else if("l"===i||"L"===i)this.curCommandType=A.LINE_TO,this.curCommandRelative="l"===i;else if("c"===i||"C"===i)this.curCommandType=A.CURVE_TO,this.curCommandRelative="c"===i;else if("s"===i||"S"===i)this.curCommandType=A.SMOOTH_CURVE_TO,this.curCommandRelative="s"===i;else if("q"===i||"Q"===i)this.curCommandType=A.QUAD_TO,this.curCommandRelative="q"===i;else if("t"===i||"T"===i)this.curCommandType=A.SMOOTH_QUAD_TO,this.curCommandRelative="t"===i;else{if("a"!==i&&"A"!==i)throw new SyntaxError(`Unexpected character "${i}" at index ${n}.`);this.curCommandType=A.ARC,this.curCommandRelative="a"===i}else e.push({type:A.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 A extends _{commands;constructor(t){super(),this.commands="string"==typeof t?A.parse(t):t}encode(){return A.encode(this.commands)}getBounds(){const t=E.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=E.REVERSE_PATH(this.commands,t),this}removeCollinear(){return this.commands=E.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===A.CLOSE_PATH)e+="z";else if(n.type===A.HORIZ_LINE_TO)e+=(n.relative?"h":"H")+n.x;else if(n.type===A.VERT_LINE_TO)e+=(n.relative?"v":"V")+n.y;else if(n.type===A.MOVE_TO)e+=(n.relative?"m":"M")+n.x+o+n.y;else if(n.type===A.LINE_TO)e+=(n.relative?"l":"L")+n.x+o+n.y;else if(n.type===A.CURVE_TO)e+=(n.relative?"c":"C")+n.x1+o+n.y1+o+n.x2+o+n.y2+o+n.x+o+n.y;else if(n.type===A.SMOOTH_CURVE_TO)e+=(n.relative?"s":"S")+n.x2+o+n.y2+o+n.x+o+n.y;else if(n.type===A.QUAD_TO)e+=(n.relative?"q":"Q")+n.x1+o+n.y1+o+n.x+o+n.y;else if(n.type===A.SMOOTH_QUAD_TO)e+=(n.relative?"t":"T")+n.x+o+n.y;else{if(n.type!==A.ARC)throw new Error(`Unexpected command type "${n?.type}" at index ${r}.`);e+=(n.relative?"a":"A")+n.rX+o+n.rY+o+n.xRot+o+ +n.lArcFlag+o+ +n.sweepFlag+o+n.x+o+n.y}}return e}(t)}static parse(t){const e=new C,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=A.LINE_TO|A.HORIZ_LINE_TO|A.VERT_LINE_TO;static DRAWING_COMMANDS=A.HORIZ_LINE_TO|A.VERT_LINE_TO|A.LINE_TO|A.CURVE_TO|A.SMOOTH_CURVE_TO|A.QUAD_TO|A.SMOOTH_QUAD_TO|A.ARC}const M={[A.MOVE_TO]:2,[A.LINE_TO]:2,[A.HORIZ_LINE_TO]:1,[A.VERT_LINE_TO]:1,[A.CLOSE_PATH]:0,[A.QUAD_TO]:4,[A.SMOOTH_QUAD_TO]:2,[A.CURVE_TO]:6,[A.SMOOTH_CURVE_TO]:4,[A.ARC]:7};class S{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 A(n).translate(t,e).encode())}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 R;class V{constructor(t){R.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,R,t,"f")}closestPoint(t){return document.body.contains(L)||document.body.append(L),P.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,R,"f")),new S(P).closestPoint(t)}}R=new WeakMap;const I=document.createElementNS("http://www.w3.org/2000/svg","svg");I.setAttribute("viewBox","0 0 100 100"),I.setAttribute("width","100"),I.setAttribute("height","100");const L=document.createElement("div");L.append(I),L.style.height="0px",L.style.position="fixed",document.body.append(L);const P=document.createElementNS("http://www.w3.org/2000/svg","path");function U(t,e){for(let[r,n]of Object.entries(e))t.setAttribute(r,n)}P.setAttribute("stroke","black"),P.setAttribute("stroke-width","1"),I.append(P);const D=new Uint8Array(16),H=[];for(let t=0;t<256;++t)H.push((t+256).toString(16).slice(1));const X=function(t,e,r){return e||t||!crypto.randomUUID?function(t,e,r){const n=(t=t||{}).random??t.rng?.()??crypto.getRandomValues(D);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(H[t[e+0]]+H[t[e+1]]+H[t[e+2]]+H[t[e+3]]+"-"+H[t[e+4]]+H[t[e+5]]+"-"+H[t[e+6]]+H[t[e+7]]+"-"+H[t[e+8]]+H[t[e+9]]+"-"+H[t[e+10]]+H[t[e+11]]+H[t[e+12]]+H[t[e+13]]+H[t[e+14]]+H[t[e+15]]).toLowerCase()}(n)}(t,e,r):crypto.randomUUID()};function Y(t){t.id="uuid-"+X()}class j{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 F{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 G{constructor(t){this.targetSVGDoc=t}get(){let t=this.targetSVGDoc.getBoundingClientRect(),e=this.targetSVGDoc.viewBox.baseVal;return t.width/e.width}}class Q{constructor(t){this.targetSVGDoc=t}get(){let t=this.targetSVGDoc.getBoundingClientRect(),e=this.targetSVGDoc.viewBox.baseVal;return t.height/e.height}}function Z(t){let e=t.parentNode;e&&e.appendChild(t)}function B(t){let e=t.parentNode;e&&e.prepend(t)}var $,z=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 W{constructor(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,"f")}toString(){return z(this,$,"f").innerHTML}set(t){z(this,$,"f").innerHTML=t}}$=new WeakMap;var k,q=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 J{constructor(t){k.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,k,t,"f")}toString(){return q(this,k,"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()!=q(this,k,"f").tagName.toLowerCase())throw new Error("Outer XML must specify an SVG element with the same tag name as the target SVG element.");[...q(this,k,"f").attributes].forEach(t=>q(this,k,"f").removeAttribute(t.name)),[...e.firstElementChild.attributes].forEach(t=>q(this,k,"f").setAttribute(t.name,t.value)),q(this,k,"f").innerHTML=e.firstElementChild.innerHTML,e.remove()}}function K(t){return t instanceof SVGGraphicsElement}k=new WeakMap;var tt=r(854);function et(t){return(0,tt.isArray)(t)&&t.every(K)}async function rt(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.
|
|
3
|
+
"version": "4.2.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": "^
|
|
18
|
-
"@babel/preset-env": "^
|
|
19
|
-
"@babel/preset-typescript": "^
|
|
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
|
-
"
|
|
34
|
+
"svg-pathdata": "^9.0.0",
|
|
35
|
+
"uuid": "^14.0.3"
|
|
35
36
|
}
|
|
36
37
|
}
|