@rnacanvas/draw.svg 3.2.0 → 3.4.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 +29 -0
- package/dist/InnerXML.d.ts +4 -4
- package/dist/InnerXML.d.ts.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/setAttributes.d.ts +7 -0
- package/dist/setAttributes.d.ts.map +1 -0
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -106,3 +106,32 @@ innerXML.toString(); // "<circle></circle><text>A</text>"
|
|
|
106
106
|
// sets the `innerHTML` property of the target SVG element
|
|
107
107
|
innerXML.set('<rect></rect><text>B</text>');
|
|
108
108
|
```
|
|
109
|
+
|
|
110
|
+
## `OuterXML`
|
|
111
|
+
|
|
112
|
+
The `OuterXML` class represents the outer XML of a target SVG element.
|
|
113
|
+
|
|
114
|
+
The critical difference between the behavior of this class
|
|
115
|
+
and the `outerHTML` property of SVG elements
|
|
116
|
+
is that the `set()` method of this class modifies the target SVG element <b>in place</b>,
|
|
117
|
+
as opposed to replacing the target SVG element with newly created SVG element(s) in the DOM tree,
|
|
118
|
+
which is what setting the `outerHTML` property does.
|
|
119
|
+
|
|
120
|
+
Thus, the `set()` method will throw if the specified outer XML does not encode exactly one SVG element
|
|
121
|
+
or if the specified outer XML encodes an SVG element with a tag name different from that of the target SVG element.
|
|
122
|
+
|
|
123
|
+
```javascript
|
|
124
|
+
var svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
|
|
125
|
+
|
|
126
|
+
svg.setAttribute('viewBox', '0 0 10 20');
|
|
127
|
+
|
|
128
|
+
svg.append(document.createElementNS('http://www.w3.org/2000/svg', 'circle'));
|
|
129
|
+
svg.append(document.createElementNS('http://www.w3.org/2000/svg', 'rect'));
|
|
130
|
+
svg.append('Some text.');
|
|
131
|
+
|
|
132
|
+
var outerXML = new OuterXML(svg);
|
|
133
|
+
|
|
134
|
+
outerXML.toString(); // '<svg viewBox="0 0 10 20"><circle></circle><rect></rect>Some text.</svg>'
|
|
135
|
+
|
|
136
|
+
outerXML.set('<svg viewBox="0 0 25 25" width="50" height="50>Different text.<path></path></svg>');
|
|
137
|
+
```
|
package/dist/InnerXML.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Represents the inner XML of a target SVG
|
|
2
|
+
* Represents the inner XML of a target SVG element.
|
|
3
3
|
*/
|
|
4
4
|
export declare class InnerXML {
|
|
5
5
|
#private;
|
|
6
|
-
constructor(
|
|
6
|
+
constructor(targetSVGElement: SVGElement);
|
|
7
7
|
/**
|
|
8
|
-
* Returns the `innerHTML` property of the target SVG
|
|
8
|
+
* Returns the `innerHTML` property of the target SVG element.
|
|
9
9
|
*/
|
|
10
10
|
toString(): string;
|
|
11
11
|
/**
|
|
12
|
-
* Sets the `innerHTML` property of the target SVG
|
|
12
|
+
* Sets the `innerHTML` property of the target SVG element.
|
|
13
13
|
*/
|
|
14
14
|
set(innerXML: string): void;
|
|
15
15
|
}
|
package/dist/InnerXML.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InnerXML.d.ts","sourceRoot":"","sources":["../src/InnerXML.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,QAAQ;;gBAGP,
|
|
1
|
+
{"version":3,"file":"InnerXML.d.ts","sourceRoot":"","sources":["../src/InnerXML.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,QAAQ;;gBAGP,gBAAgB,EAAE,UAAU;IAIxC;;OAEG;IACH,QAAQ,IAAI,MAAM;IAIlB;;OAEG;IACH,GAAG,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;CAG5B"}
|
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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E,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"}
|
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,(()=>(()=>{"use strict";var t={d:(e,i)=>{for(var r in i)t.o(i,r)&&!t.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:i[r]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};t.r(e),t.d(e,{CoordinateSystem:()=>
|
|
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,(()=>(()=>{"use strict";var t={d:(e,i)=>{for(var r in i)t.o(i,r)&&!t.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:i[r]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};function i(t,e){for(let[i,r]of Object.entries(e))t.setAttribute(i,r)}t.r(e),t.d(e,{CoordinateSystem:()=>u,HorizontalClientScaling:()=>d,InnerXML:()=>y,OuterXML:()=>b,Scaling:()=>g,VerticalClientScaling:()=>f,assignUUID:()=>c,bringToFront:()=>m,sendToBack:()=>w,setAttributes:()=>i});const r={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};var n,o=new Uint8Array(16);function a(){if(!n&&!(n="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 n(o)}for(var s=[],h=0;h<256;++h)s.push((h+256).toString(16).slice(1));const l=function(t,e,i){if(r.randomUUID&&!e&&!t)return r.randomUUID();var n=(t=t||{}).random||(t.rng||a)();if(n[6]=15&n[6]|64,n[8]=63&n[8]|128,e){i=i||0;for(var o=0;o<16;++o)e[i+o]=n[o];return e}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()}(n)};function c(t){t.id="uuid-"+l()}class u{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 d{constructor(t){this.targetSVGDoc=t}get(){let t=this.targetSVGDoc.getBoundingClientRect(),e=this.targetSVGDoc.viewBox.baseVal;return t.width/e.width}}class f{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 w(t){let e=t.parentNode;e&&e.prepend(t)}var p,C=function(t,e,i,r){if("a"===i&&!r)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!r:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===i?r:"a"===i?r.call(t):r?r.value:e.get(t)};class y{constructor(t){p.set(this,void 0),function(t,e,i,r,n){if("m"===r)throw new TypeError("Private method is not writable");if("a"===r&&!n)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!n:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");"a"===r?n.call(t,i):n?n.value=i:e.set(t,i)}(this,p,t,"f")}toString(){return C(this,p,"f").innerHTML}set(t){C(this,p,"f").innerHTML=t}}p=new WeakMap;var S,v=function(t,e,i,r){if("a"===i&&!r)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!r:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===i?r:"a"===i?r.call(t):r?r.value:e.get(t)};class b{constructor(t){S.set(this,void 0),function(t,e,i,r,n){if("m"===r)throw new TypeError("Private method is not writable");if("a"===r&&!n)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!n:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");"a"===r?n.call(t,i):n?n.value=i:e.set(t,i)}(this,S,t,"f")}toString(){return v(this,S,"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,S,"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,S,"f").attributes].forEach((t=>v(this,S,"f").removeAttribute(t.name))),[...e.firstElementChild.attributes].forEach((t=>v(this,S,"f").setAttribute(t.name,t.value))),v(this,S,"f").innerHTML=e.firstElementChild.innerHTML,e.remove()}}return S=new WeakMap,e})()));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setAttributes.d.ts","sourceRoot":"","sources":["../src/setAttributes.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,wBAAgB,aAAa,CAAC,gBAAgB,EAAE,UAAU,EAAE,UAAU,EAAE;IAAE,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,GAAG,IAAI,CAIxG"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rnacanvas/draw.svg",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.4.0",
|
|
4
4
|
"description": "SVG drawing utilities",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
"webpack-cli": "^5.1.4"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
+
"@rnacanvas/value-check": "^1.14.1",
|
|
30
31
|
"@svgdotjs/svg.js": "^3.2.0",
|
|
31
32
|
"uuid": "^10.0.0"
|
|
32
33
|
}
|