@rnacanvas/draw.svg 3.7.1 → 3.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -17,6 +17,53 @@ import { bringToFront, sendToBack } from '@rnacanvas/draw.svg';
17
17
  import { InnerXML, OuterXML } from '@rnacanvas/draw.svg';
18
18
  ```
19
19
 
20
+ ## `class Path`
21
+
22
+ Wraps an SVG path element.
23
+
24
+ ### `readonly domNode`
25
+
26
+ The wrapped SVG path element.
27
+
28
+ ```javascript
29
+ var domNode = document.createElement('http://www.w3.org/2000/svg', 'path');
30
+
31
+ var path = new Path(domNode);
32
+
33
+ path.domNode === domNode; // true
34
+ ```
35
+
36
+ ### `closestPoint()`
37
+
38
+ Calculates and returns the closest point along the path to a given point
39
+ (as well as returns the length along the path that the closest point is).
40
+
41
+ ```javascript
42
+ // make the path a horizontal line
43
+ path.domNode.setAttribute('d', 'M 0 0 H 10');
44
+
45
+ var p = path.closestPoint({ x: 5, y: 5 });
46
+
47
+ p; // { x: 5, y: 0, length: 5 }
48
+ ```
49
+
50
+ A `precision` option can also be specified,
51
+ which roughly controls the margin for error in the closest point calculation.
52
+
53
+ (Lower precision improves the speed of calculation.)
54
+
55
+ ```javascript
56
+ // make the path a horizontal line
57
+ path.domNode.setAttribute('d', 'M 0 0 H 100');
58
+
59
+ var p = path.closestPoint({ x: 33, y: 33 }, { precision: 20 });
60
+
61
+ // is within 20 of the true closest point
62
+ p; // { x: 40, y: 0, length: 40 }
63
+ ```
64
+
65
+ This method will throw if a precision of 0 or a negative precision is specified.
66
+
20
67
  ## `setAttributes()`
21
68
 
22
69
  Set multiple attributes of a target SVG element at once.
@@ -161,8 +208,9 @@ var svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
161
208
  var canvas = await drawOnCanvas(svg);
162
209
  ```
163
210
 
164
- The dimensions of the canvas element (i.e., its `width` and `height` attributes)
165
- are made to match the dimensions of the passed in SVG document.
211
+ The `width` and `height` attributes of the returned canvas element
212
+ will match the `width` and `height` attributes of the passed in SVG document
213
+ (in units of pixels).
166
214
 
167
- At this time the passed in SVG document is drawn on the canvas with horizontal and vertical scalings of 1
168
- regardless of what the horizontal and vertical scalings of the SVG document actually are.
215
+ This function might possibly fail,
216
+ such as if the dimensions of the passed in SVG document are too big.
package/dist/Path.d.ts ADDED
@@ -0,0 +1,27 @@
1
+ export declare class Path {
2
+ readonly domNode: SVGPathElement;
3
+ constructor(domNode: SVGPathElement);
4
+ /**
5
+ * Returns the closest point along the path to the given point
6
+ * (as well as the length along the path that the closest point is).
7
+ *
8
+ * The precision option roughly corresponds to the margin for error in the closest point calculation.
9
+ *
10
+ * (Higher margin for error improves the speed of calculation.)
11
+ *
12
+ * This method will throw for non-positive precisions.
13
+ */
14
+ closestPoint(p: Point, options?: {
15
+ precision?: number;
16
+ }): {
17
+ x: number;
18
+ y: number;
19
+ length: number;
20
+ };
21
+ }
22
+ type Point = {
23
+ x: number;
24
+ y: number;
25
+ };
26
+ export {};
27
+ //# sourceMappingURL=Path.d.ts.map
@@ -0,0 +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;;;;;;;;;OASG;IACH,YAAY,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,EAAE;QAAE,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE;;;;;CAuBxD;AAED,KAAK,KAAK,GAAG;IACX,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACX,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import { Path } from './Path';
2
+ export { Path };
1
3
  import { setAttributes } from './setAttributes';
2
4
  export { setAttributes };
3
5
  import { assignUUID } from './assignUUID';
@@ -1 +1 @@
1
- {"version":3,"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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={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)}function h(t){return l(t)&&0==t.length}function d(t){return l(t)&&t.length>0}function f(t){return l(t)&&t.every(r)}function g(t){return f(t)&&t.length>0}function m(t){return l(t)&&t.every(n)}function p(t){return l(t)&&t.every(i)}function y(t){return l(t)&&t.every(s)}function w(t){return y(t)&&t.length>0}return t.r(e),t.d(e,{isArray:()=>l,isEmptyArray:()=>h,isFiniteNumber:()=>n,isFiniteNumbersArray:()=>m,isNonEmptyArray:()=>d,isNonEmptyNumbersArray:()=>g,isNonEmptyStringsArray:()=>w,isNonFiniteNumber:()=>i,isNonFiniteNumbersArray:()=>p,isNonNegativeFiniteNumber:()=>a,isNonNullObject:()=>c,isNullish:()=>u,isNumber:()=>r,isNumbersArray:()=>f,isPositiveFiniteNumber:()=>o,isString:()=>s,isStringsArray:()=>y}),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";function t(t,e){for(let[r,n]of Object.entries(e))t.setAttribute(r,n)}r.r(n),r.d(n,{CoordinateSystem:()=>h,HorizontalClientScaling:()=>f,InnerXML:()=>v,OuterXML:()=>C,Scaling:()=>d,VerticalClientScaling:()=>g,assignUUID:()=>l,bringToFront:()=>m,drawOnCanvas:()=>D,isSVGGraphicsElement:()=>V,isSVGGraphicsElementsArray:()=>E,sendToBack:()=>p,setAttributes:()=>t});const e={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};var i,o=new Uint8Array(16);function a(){if(!i&&!(i="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return i(o)}for(var s=[],u=0;u<256;++u)s.push((u+256).toString(16).slice(1));const c=function(t,r,n){if(e.randomUUID&&!r&&!t)return e.randomUUID();var i=(t=t||{}).random||(t.rng||a)();if(i[6]=15&i[6]|64,i[8]=63&i[8]|128,r){n=n||0;for(var o=0;o<16;++o)r[n+o]=i[o];return r}return function(t,e=0){return(s[t[e+0]]+s[t[e+1]]+s[t[e+2]]+s[t[e+3]]+"-"+s[t[e+4]]+s[t[e+5]]+"-"+s[t[e+6]]+s[t[e+7]]+"-"+s[t[e+8]]+s[t[e+9]]+"-"+s[t[e+10]]+s[t[e+11]]+s[t[e+12]]+s[t[e+13]]+s[t[e+14]]+s[t[e+15]]).toLowerCase()}(i)};function l(t){t.id="uuid-"+c()}class h{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 d{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 f{constructor(t){this.targetSVGDoc=t}get(){let t=this.targetSVGDoc.getBoundingClientRect(),e=this.targetSVGDoc.viewBox.baseVal;return t.width/e.width}}class g{constructor(t){this.targetSVGDoc=t}get(){let t=this.targetSVGDoc.getBoundingClientRect(),e=this.targetSVGDoc.viewBox.baseVal;return t.height/e.height}}function m(t){let e=t.parentNode;e&&e.appendChild(t)}function p(t){let e=t.parentNode;e&&e.prepend(t)}var y,w=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){y.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,y,t,"f")}toString(){return w(this,y,"f").innerHTML}set(t){w(this,y,"f").innerHTML=t}}y=new WeakMap;var b,S=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 C{constructor(t){b.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,b,t,"f")}toString(){return S(this,b,"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()!=S(this,b,"f").tagName.toLowerCase())throw new Error("Outer XML must specify an SVG element with the same tag name as the target SVG element.");[...S(this,b,"f").attributes].forEach(t=>S(this,b,"f").removeAttribute(t.name)),[...e.firstElementChild.attributes].forEach(t=>S(this,b,"f").setAttribute(t.name,t.value)),S(this,b,"f").innerHTML=e.firstElementChild.innerHTML,e.remove()}}function V(t){return t instanceof SVGGraphicsElement}b=new WeakMap;var x=r(854);function E(t){return(0,x.isArray)(t)&&t.every(V)}var G=function(t,e,r,n){return new(r||(r=Promise))(function(i,o){function a(t){try{u(n.next(t))}catch(t){o(t)}}function s(t){try{u(n.throw(t))}catch(t){o(t)}}function u(t){var e;t.done?i(t.value):(e=t.value,e instanceof r?e:new r(function(t){t(e)})).then(a,s)}u((n=n.apply(t,e||[])).next())})};function D(t){return G(this,void 0,void 0,function*(){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),yield 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:()=>f,average:()=>n,degrees:()=>m,isBetweenExclusive:()=>h,isBetweenInclusive:()=>l,max:()=>c,mean:()=>n,median:()=>s,min:()=>u,radians:()=>y,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 y(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 null==t}function c(t){return"object"==typeof t&&null!==t}function l(t){return Array.isArray(t)}function h(t){return l(t)&&0==t.length}function f(t){return l(t)&&t.length>0}function d(t){return l(t)&&t.every(r)}function g(t){return d(t)&&t.length>0}function m(t){return l(t)&&t.every(n)}function y(t){return l(t)&&t.every(i)}function p(t){return l(t)&&t.every(s)}function b(t){return p(t)&&t.length>0}return t.r(e),t.d(e,{isArray:()=>l,isEmptyArray:()=>h,isFiniteNumber:()=>n,isFiniteNumbersArray:()=>m,isNonEmptyArray:()=>f,isNonEmptyNumbersArray:()=>g,isNonEmptyStringsArray:()=>b,isNonFiniteNumber:()=>i,isNonFiniteNumbersArray:()=>y,isNonNegativeFiniteNumber:()=>a,isNonNullObject:()=>c,isNullish:()=>u,isNumber:()=>r,isNumbersArray:()=>d,isPositiveFiniteNumber:()=>o,isString:()=>s,isStringsArray:()=>p}),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,{CoordinateSystem:()=>d,HorizontalClientScaling:()=>m,InnerXML:()=>S,OuterXML:()=>C,Path:()=>e,Scaling:()=>g,VerticalClientScaling:()=>y,assignUUID:()=>f,bringToFront:()=>p,drawOnCanvas:()=>M,isSVGGraphicsElement:()=>P,isSVGGraphicsElementsArray:()=>O,sendToBack:()=>b,setAttributes:()=>i});var t=r(725);class e{constructor(t){this.domNode=t}closestPoint(e,r){var n;let i=this.domNode.getPointAtLength(0),o={x:i.x,y:i.y,length:0},a=null!==(n=null==r?void 0:r.precision)&&void 0!==n?n:5;if(a<=0)throw new Error(`Precision must be positive: ${a}.`);let s=this.domNode.getTotalLength();for(let r=a;r<=s;r+=a){let n=this.domNode.getPointAtLength(r);(0,t.distance)(e,n)<(0,t.distance)(e,o)&&(o={x:n.x,y:n.y,length:r})}return o}}function i(t,e){for(let[r,n]of Object.entries(e))t.setAttribute(r,n)}const o={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};var a,s=new Uint8Array(16);function u(){if(!a&&!(a="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return a(s)}for(var c=[],l=0;l<256;++l)c.push((l+256).toString(16).slice(1));const h=function(t,e,r){if(o.randomUUID&&!e&&!t)return o.randomUUID();var n=(t=t||{}).random||(t.rng||u)();if(n[6]=15&n[6]|64,n[8]=63&n[8]|128,e){r=r||0;for(var i=0;i<16;++i)e[r+i]=n[i];return e}return function(t,e=0){return(c[t[e+0]]+c[t[e+1]]+c[t[e+2]]+c[t[e+3]]+"-"+c[t[e+4]]+c[t[e+5]]+"-"+c[t[e+6]]+c[t[e+7]]+"-"+c[t[e+8]]+c[t[e+9]]+"-"+c[t[e+10]]+c[t[e+11]]+c[t[e+12]]+c[t[e+13]]+c[t[e+14]]+c[t[e+15]]).toLowerCase()}(n)};function f(t){t.id="uuid-"+h()}class d{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 g{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 m{constructor(t){this.targetSVGDoc=t}get(){let t=this.targetSVGDoc.getBoundingClientRect(),e=this.targetSVGDoc.viewBox.baseVal;return t.width/e.width}}class y{constructor(t){this.targetSVGDoc=t}get(){let t=this.targetSVGDoc.getBoundingClientRect(),e=this.targetSVGDoc.viewBox.baseVal;return t.height/e.height}}function p(t){let e=t.parentNode;e&&e.appendChild(t)}function b(t){let e=t.parentNode;e&&e.prepend(t)}var v,w=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 S{constructor(t){v.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,v,t,"f")}toString(){return w(this,v,"f").innerHTML}set(t){w(this,v,"f").innerHTML=t}}v=new WeakMap;var x,N=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 C{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 N(this,x,"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()!=N(this,x,"f").tagName.toLowerCase())throw new Error("Outer XML must specify an SVG element with the same tag name as the target SVG element.");[...N(this,x,"f").attributes].forEach(t=>N(this,x,"f").removeAttribute(t.name)),[...e.firstElementChild.attributes].forEach(t=>N(this,x,"f").setAttribute(t.name,t.value)),N(this,x,"f").innerHTML=e.firstElementChild.innerHTML,e.remove()}}function P(t){return t instanceof SVGGraphicsElement}x=new WeakMap;var V=r(854);function O(t){return(0,V.isArray)(t)&&t.every(P)}var j=function(t,e,r,n){return new(r||(r=Promise))(function(i,o){function a(t){try{u(n.next(t))}catch(t){o(t)}}function s(t){try{u(n.throw(t))}catch(t){o(t)}}function u(t){var e;t.done?i(t.value):(e=t.value,e instanceof r?e:new r(function(t){t(e)})).then(a,s)}u((n=n.apply(t,e||[])).next())})};function M(t){return j(this,void 0,void 0,function*(){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),yield 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": "3.7.1",
3
+ "version": "3.8.1",
4
4
  "description": "SVG drawing utilities",
5
5
  "repository": {
6
6
  "type": "git",
@@ -28,6 +28,7 @@
28
28
  "webpack-cli": "^6.0.1"
29
29
  },
30
30
  "dependencies": {
31
+ "@rnacanvas/points": "^1.12.0",
31
32
  "@rnacanvas/value-check": "^1.14.1",
32
33
  "@svgdotjs/svg.js": "^3.2.0",
33
34
  "uuid": "^10.0.0"