@rnacanvas/draw.svg 3.5.0 → 3.7.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/dist/drawOnCanvas.d.ts +10 -0
- package/dist/drawOnCanvas.d.ts.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/isSVGGraphicsElementsArray.d.ts +7 -0
- package/dist/isSVGGraphicsElementsArray.d.ts.map +1 -0
- package/package.json +6 -5
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a new HTML canvas element and draws the passed in SVG document on it.
|
|
3
|
+
*
|
|
4
|
+
* The dimensions of the canvas element are made to match those of the SVG document.
|
|
5
|
+
*
|
|
6
|
+
* At this time the SVG document is simply drawn on the canvas with horizontal and vertical scalings of 1
|
|
7
|
+
* regardless of what scalings the SVG document might actually have.
|
|
8
|
+
*/
|
|
9
|
+
export declare function drawOnCanvas(svg: SVGSVGElement): Promise<HTMLCanvasElement | never>;
|
|
10
|
+
//# sourceMappingURL=drawOnCanvas.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"drawOnCanvas.d.ts","sourceRoot":"","sources":["../src/drawOnCanvas.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,wBAAsB,YAAY,CAAC,GAAG,EAAE,aAAa,GAAG,OAAO,CAAC,iBAAiB,GAAG,KAAK,CAAC,CAqDzF"}
|
package/dist/index.d.ts
CHANGED
|
@@ -20,4 +20,8 @@ import { OuterXML } from './OuterXML';
|
|
|
20
20
|
export { OuterXML };
|
|
21
21
|
import { isSVGGraphicsElement } from './isSVGGraphicsElement';
|
|
22
22
|
export { isSVGGraphicsElement };
|
|
23
|
+
import { isSVGGraphicsElementsArray } from './isSVGGraphicsElementsArray';
|
|
24
|
+
export { isSVGGraphicsElementsArray };
|
|
25
|
+
import { drawOnCanvas } from './drawOnCanvas';
|
|
26
|
+
export { drawOnCanvas };
|
|
23
27
|
//# sourceMappingURL=index.d.ts.map
|
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,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"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"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"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,
|
|
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 c(t){return null==t}function u(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 w(t){return l(t)&&t.every(s)}function y(t){return w(t)&&t.length>0}return t.r(e),t.d(e,{isArray:()=>l,isEmptyArray:()=>h,isFiniteNumber:()=>n,isFiniteNumbersArray:()=>m,isNonEmptyArray:()=>d,isNonEmptyNumbersArray:()=>g,isNonEmptyStringsArray:()=>y,isNonFiniteNumber:()=>i,isNonFiniteNumbersArray:()=>p,isNonNegativeFiniteNumber:()=>a,isNonNullObject:()=>u,isNullish:()=>c,isNumber:()=>r,isNumbersArray:()=>f,isPositiveFiniteNumber:()=>o,isString:()=>s,isStringsArray:()=>w}),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:()=>G,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=[],c=0;c<256;++c)s.push((c+256).toString(16).slice(1));const u=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-"+u()}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 w,y=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){w.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,w,t,"f")}toString(){return y(this,w,"f").innerHTML}set(t){y(this,w,"f").innerHTML=t}}w=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 G(t){return(0,x.isArray)(t)&&t.every(V)}var E=function(t,e,r,n){return new(r||(r=Promise))(function(i,o){function a(t){try{c(n.next(t))}catch(t){o(t)}}function s(t){try{c(n.throw(t))}catch(t){o(t)}}function c(t){var e;t.done?i(t.value):(e=t.value,e instanceof r?e:new r(function(t){t(e)})).then(a,s)}c((n=n.apply(t,e||[])).next())})};function D(t){return E(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);let r=t.cloneNode(!0);if(!(r instanceof SVGSVGElement))throw new Error("Unable to clone SVG document");new d(r).set(1),e.width=r.viewBox.baseVal.width,e.height=r.viewBox.baseVal.height;let n=e.getContext("2d");if(!n)throw new Error("Unable to get canvas context.");let i=(new XMLSerializer).serializeToString(r),o=new Image;return o.src="data:image/svg+xml;charset=utf-8,"+encodeURIComponent(i),yield o.decode(),n.drawImage(o,0,0,r.viewBox.baseVal.width,r.viewBox.baseVal.height),e.remove(),e.style.position="",e.style.display="",e.style.pointerEvents="",e})}})(),n})());
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns true if and only if the value is an array of SVG graphics elements.
|
|
3
|
+
*
|
|
4
|
+
* Vacuously returns true for an empty array.
|
|
5
|
+
*/
|
|
6
|
+
export declare function isSVGGraphicsElementsArray(value: unknown): value is SVGGraphicsElement[];
|
|
7
|
+
//# sourceMappingURL=isSVGGraphicsElementsArray.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isSVGGraphicsElementsArray.d.ts","sourceRoot":"","sources":["../src/isSVGGraphicsElementsArray.ts"],"names":[],"mappings":"AAIA;;;;GAIG;AACH,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,kBAAkB,EAAE,CAKxF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rnacanvas/draw.svg",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.7.0",
|
|
4
4
|
"description": "SVG drawing utilities",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -18,13 +18,14 @@
|
|
|
18
18
|
"@babel/preset-env": "^7.23.7",
|
|
19
19
|
"@babel/preset-typescript": "^7.23.3",
|
|
20
20
|
"@types/uuid": "^10.0.0",
|
|
21
|
-
"babel-jest": "^
|
|
22
|
-
"
|
|
23
|
-
"jest
|
|
21
|
+
"babel-jest": "^30.1.2",
|
|
22
|
+
"canvas": "^3.2.0",
|
|
23
|
+
"jest": "^30.1.3",
|
|
24
|
+
"jest-environment-jsdom": "^30.1.2",
|
|
24
25
|
"ts-loader": "^9.5.1",
|
|
25
26
|
"typescript": "^5.3.3",
|
|
26
27
|
"webpack": "^5.89.0",
|
|
27
|
-
"webpack-cli": "^
|
|
28
|
+
"webpack-cli": "^6.0.1"
|
|
28
29
|
},
|
|
29
30
|
"dependencies": {
|
|
30
31
|
"@rnacanvas/value-check": "^1.14.1",
|