path2d-polyfill
Advanced tools
Comparing version 0.1.2 to 0.1.3
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(e.path2dPolyfill={})}(this,function(e){"use strict";var t={a:7,c:6,h:1,l:2,m:2,q:4,s:4,t:2,v:1,z:0},n=/([astvzqmhlc])([^astvzqmhlc]*)/gi,a=/-?[0-9]*\.?[0-9]+(?:e[-+]?\d+)?/gi;function r(e){var r=[],o=(""+e).trim();return"M"!==o[0]&&"m"!==o[0]?r:(o.replace(n,function(e,n,o){var i=n.toLowerCase();if(o=function(e){var t=e.match(a);return t?t.map(Number):[]}(o),"m"===i&&o.length>2&&(r.push([n].concat(o.splice(0,2))),i="l",n="m"===n?"l":"L"),o.length<t[i])return"";for(r.push([n].concat(o.splice(0,t[i])));o.length>=t[i]&&o.length&&t[i];)r.push([n].concat(o.splice(0,t[i])));return""}),r)}var o=function(){function e(e,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}}return function(t,n,a){return n&&e(t.prototype,n),a&&e(t,a),t}}();function i(e){if(Array.isArray(e)){for(var t=0,n=Array(e.length);t<e.length;t++)n[t]=e[t];return n}return Array.from(e)}function s(e,t){var n=e.x*Math.cos(t)-e.y*Math.sin(t),a=e.y*Math.cos(t)+e.x*Math.sin(t);e.x=n,e.y=a}function c(e,t,n){e.x+=t,e.y+=n}function u(e){if(e&&(!e.Path2D||!function(e){var t=e.document.createElement("canvas"),n=t.getContext("2d"),a=new e.Path2D("M0 0 L1 1");n.strokeStyle="red",n.lineWidth=1,n.stroke(a);var r=255===n.getImageData(0,0,1,1).data[0];return t.parentNode.removeChild(t),r}(e))){var t=function(){function e(t){var n;((function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")})(this,e),this.segments=[],t&&t instanceof e)?(n=this.segments).push.apply(n,i(t.segments)):t&&(this.segments=r(t))}return o(e,[{key:"addPath",value:function(t){var n;t&&t instanceof e&&(n=this.segments).push.apply(n,i(t.segments))}},{key:"moveTo",value:function(e,t){this.segments.push(["M",e,t])}},{key:"lineTo",value:function(e,t){this.segments.push(["L",e,t])}},{key:"arc",value:function(e,t,n,a,r,o){this.segments.push(["AC",e,t,n,a,r,!!o])}},{key:"arcTo",value:function(e,t,n,a,r){this.segments.push(["AT",e,t,n,a,r])}},{key:"closePath",value:function(){this.segments.push(["Z"])}},{key:"bezierCurveTo",value:function(e,t,n,a,r,o){this.segments.push(["C",e,t,n,a,r,o])}},{key:"quadraticCurveTo",value:function(e,t,n,a){this.segments.push(["Q",e,t,n,a])}},{key:"rect",value:function(e,t,n,a){this.segments.push(["R",e,t,n,a])}}]),e}(),n=e.CanvasRenderingContext2D.prototype.fill,a=e.CanvasRenderingContext2D.prototype.stroke;e.CanvasRenderingContext2D.prototype.fill=function(){for(var e=arguments.length,t=Array(e),a=0;a<e;a++)t[a]=arguments[a];var r="nonzero";0===t.length||1===t.length&&"string"==typeof t[0]?n.apply(this,t):(2===arguments.length&&(r=t[1]),u(this,t[0].segments),n.call(this,r))},e.CanvasRenderingContext2D.prototype.stroke=function(e){e?(u(this,e.segments),a.call(this)):a.call(this)},e.Path2D=t}function u(e,t){var n=void 0,a=void 0,r=void 0,o=void 0,i=void 0,u=void 0,l=void 0,v=void 0,h=void 0,f=void 0,d=void 0,y=void 0,p=void 0,g=void 0,m=void 0,b=void 0,k=void 0,x=void 0,C=void 0,T=void 0,M=void 0,q={x:0,y:0};"S"!==m&&"s"!==m&&"C"!==m&&"c"!==m&&(k=null,x=null),"T"!==m&&"t"!==m&&"Q"!==m&&"q"!==m&&(C=null,T=null),e.beginPath();for(var P=0;P<t.length;++P){var w=t[P];switch(m=w[0]){case"m":l+=w[1],h+=w[2],e.moveTo(l,h);break;case"M":l=w[1],h=w[2],e.moveTo(l,h);break;case"l":l+=w[1],h+=w[2],e.lineTo(l,h);break;case"L":l=w[1],h=w[2],e.lineTo(l,h);break;case"H":l=w[1],e.lineTo(l,h);break;case"h":l+=w[1],e.lineTo(l,h);break;case"V":h=w[1],e.lineTo(l,h);break;case"v":h+=w[1],e.lineTo(l,h);break;case"a":case"A":"a"===m?(l+=w[6],h+=w[7]):(l=w[6],h=w[7]),d=w[1],r=w[4],o=w[5],c(i={x:l,y:h},-q.x,-q.y),s(i,-(u=Math.atan2(i.y,i.x))),y=i.x/2,(b={x:0,y:0}).x=i.x/2,b.y=o&&!r||!o&&r?Math.sqrt(d*d-y*y):-Math.sqrt(d*d-y*y),a=Math.atan2(-b.y,-b.x),n=Math.atan2(i.y-b.y,i.x-b.x),a+=u,n+=u,s(i,u),s(b,u),c(i,q.x,q.y),c(b,q.x,q.y),e.arc(b.x,b.y,d,a,n,!o);break;case"C":k=w[3],x=w[4],l=w[5],h=w[6],e.bezierCurveTo(w[1],w[2],k,x,l,h);break;case"c":e.bezierCurveTo(w[1]+l,w[2]+h,w[3]+l,w[4]+h,w[5]+l,w[6]+h),k=w[3]+l,x=w[4]+h,l+=w[5],h+=w[6];break;case"S":null!==k&&null!==k||(k=l,x=h),e.bezierCurveTo(2*l-k,2*h-x,w[1],w[2],w[3],w[4]),k=w[1],x=w[2],l=w[3],h=w[4];break;case"s":null!==k&&null!==k||(k=l,x=h),e.bezierCurveTo(2*l-k,2*h-x,w[1]+l,w[2]+h,w[3]+l,w[4]+h),k=w[1]+l,x=w[2]+h,l+=w[3],h+=w[4];break;case"Q":C=w[1],T=w[2],l=w[3],h=w[4],e.quadraticCurveTo(C,T,l,h);break;case"q":C=w[1]+l,T=w[2]+h,l+=w[3],h+=w[4],e.quadraticCurveTo(C,T,l,h);break;case"T":null!==C&&null!==C||(C=l,T=h),C=2*l-C,T=2*h-T,l=w[1],h=w[2],e.quadraticCurveTo(C,T,l,h);break;case"t":null!==C&&null!==C||(C=l,T=h),C=2*l-C,T=2*h-T,l+=w[1],h+=w[2],e.quadraticCurveTo(C,T,l,h);break;case"z":case"Z":e.closePath();break;case"AC":l=w[1],h=w[2],d=w[3],a=w[4],n=w[5],M=w[6],e.arc(l,h,d,a,n,M);break;case"AT":v=w[1],f=w[2],l=w[3],h=w[4],d=w[5],e.arcTo(v,f,l,h,d);break;case"R":l=w[1],h=w[2],p=w[3],g=w[4],e.rect(l,h,p,g)}q.x=l,q.y=h}}}"undefined"!=typeof window&&u(window),e.path2dPolyfill=u,e.parsePath=r,Object.defineProperty(e,"__esModule",{value:!0})}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(e.path2dPolyfill={})}(this,function(e){"use strict";var t={a:7,c:6,h:1,l:2,m:2,q:4,s:4,t:2,v:1,z:0},n=/([astvzqmhlc])([^astvzqmhlc]*)/gi,a=/-?[0-9]*\.?[0-9]+(?:e[-+]?\d+)?/gi;function r(e){var r=[],o=(""+e).trim();return"M"!==o[0]&&"m"!==o[0]?r:(o.replace(n,function(e,n,o){var i=n.toLowerCase();if(o=function(e){var t=e.match(a);return t?t.map(Number):[]}(o),"m"===i&&o.length>2&&(r.push([n].concat(o.splice(0,2))),i="l",n="m"===n?"l":"L"),o.length<t[i])return"";for(r.push([n].concat(o.splice(0,t[i])));o.length>=t[i]&&o.length&&t[i];)r.push([n].concat(o.splice(0,t[i])));return""}),r)}var o=function(){function e(e,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}}return function(t,n,a){return n&&e(t.prototype,n),a&&e(t,a),t}}();function i(e){if(Array.isArray(e)){for(var t=0,n=Array(e.length);t<e.length;t++)n[t]=e[t];return n}return Array.from(e)}function s(e,t){var n=e.x*Math.cos(t)-e.y*Math.sin(t),a=e.y*Math.cos(t)+e.x*Math.sin(t);e.x=n,e.y=a}function c(e,t,n){e.x+=t,e.y+=n}function u(e){if(e&&(!e.Path2D||!function(e){var t=e.document.createElement("canvas").getContext("2d"),n=new e.Path2D("M0 0 L1 1");return t.strokeStyle="red",t.lineWidth=1,t.stroke(n),255===t.getImageData(0,0,1,1).data[0]}(e))){var t=function(){function e(t){var n;((function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")})(this,e),this.segments=[],t&&t instanceof e)?(n=this.segments).push.apply(n,i(t.segments)):t&&(this.segments=r(t))}return o(e,[{key:"addPath",value:function(t){var n;t&&t instanceof e&&(n=this.segments).push.apply(n,i(t.segments))}},{key:"moveTo",value:function(e,t){this.segments.push(["M",e,t])}},{key:"lineTo",value:function(e,t){this.segments.push(["L",e,t])}},{key:"arc",value:function(e,t,n,a,r,o){this.segments.push(["AC",e,t,n,a,r,!!o])}},{key:"arcTo",value:function(e,t,n,a,r){this.segments.push(["AT",e,t,n,a,r])}},{key:"closePath",value:function(){this.segments.push(["Z"])}},{key:"bezierCurveTo",value:function(e,t,n,a,r,o){this.segments.push(["C",e,t,n,a,r,o])}},{key:"quadraticCurveTo",value:function(e,t,n,a){this.segments.push(["Q",e,t,n,a])}},{key:"rect",value:function(e,t,n,a){this.segments.push(["R",e,t,n,a])}}]),e}(),n=e.CanvasRenderingContext2D.prototype.fill,a=e.CanvasRenderingContext2D.prototype.stroke;e.CanvasRenderingContext2D.prototype.fill=function(){for(var e=arguments.length,t=Array(e),a=0;a<e;a++)t[a]=arguments[a];var r="nonzero";0===t.length||1===t.length&&"string"==typeof t[0]?n.apply(this,t):(2===arguments.length&&(r=t[1]),u(this,t[0].segments),n.call(this,r))},e.CanvasRenderingContext2D.prototype.stroke=function(e){e?(u(this,e.segments),a.call(this)):a.call(this)},e.Path2D=t}function u(e,t){var n=void 0,a=void 0,r=void 0,o=void 0,i=void 0,u=void 0,l=void 0,h=void 0,v=void 0,f=void 0,d=void 0,y=void 0,p=void 0,g=void 0,m=void 0,b=void 0,k=void 0,x=void 0,T=void 0,C=void 0,M=void 0,q={x:0,y:0};"S"!==m&&"s"!==m&&"C"!==m&&"c"!==m&&(k=null,x=null),"T"!==m&&"t"!==m&&"Q"!==m&&"q"!==m&&(T=null,C=null),e.beginPath();for(var P=0;P<t.length;++P){var w=t[P];switch(m=w[0]){case"m":l+=w[1],v+=w[2],e.moveTo(l,v);break;case"M":l=w[1],v=w[2],e.moveTo(l,v);break;case"l":l+=w[1],v+=w[2],e.lineTo(l,v);break;case"L":l=w[1],v=w[2],e.lineTo(l,v);break;case"H":l=w[1],e.lineTo(l,v);break;case"h":l+=w[1],e.lineTo(l,v);break;case"V":v=w[1],e.lineTo(l,v);break;case"v":v+=w[1],e.lineTo(l,v);break;case"a":case"A":"a"===m?(l+=w[6],v+=w[7]):(l=w[6],v=w[7]),d=w[1],r=w[4],o=w[5],c(i={x:l,y:v},-q.x,-q.y),s(i,-(u=Math.atan2(i.y,i.x))),y=i.x/2,(b={x:0,y:0}).x=i.x/2,b.y=o&&!r||!o&&r?Math.sqrt(d*d-y*y):-Math.sqrt(d*d-y*y),a=Math.atan2(-b.y,-b.x),n=Math.atan2(i.y-b.y,i.x-b.x),a+=u,n+=u,s(i,u),s(b,u),c(i,q.x,q.y),c(b,q.x,q.y),e.arc(b.x,b.y,d,a,n,!o);break;case"C":k=w[3],x=w[4],l=w[5],v=w[6],e.bezierCurveTo(w[1],w[2],k,x,l,v);break;case"c":e.bezierCurveTo(w[1]+l,w[2]+v,w[3]+l,w[4]+v,w[5]+l,w[6]+v),k=w[3]+l,x=w[4]+v,l+=w[5],v+=w[6];break;case"S":null!==k&&null!==k||(k=l,x=v),e.bezierCurveTo(2*l-k,2*v-x,w[1],w[2],w[3],w[4]),k=w[1],x=w[2],l=w[3],v=w[4];break;case"s":null!==k&&null!==k||(k=l,x=v),e.bezierCurveTo(2*l-k,2*v-x,w[1]+l,w[2]+v,w[3]+l,w[4]+v),k=w[1]+l,x=w[2]+v,l+=w[3],v+=w[4];break;case"Q":T=w[1],C=w[2],l=w[3],v=w[4],e.quadraticCurveTo(T,C,l,v);break;case"q":T=w[1]+l,C=w[2]+v,l+=w[3],v+=w[4],e.quadraticCurveTo(T,C,l,v);break;case"T":null!==T&&null!==T||(T=l,C=v),T=2*l-T,C=2*v-C,l=w[1],v=w[2],e.quadraticCurveTo(T,C,l,v);break;case"t":null!==T&&null!==T||(T=l,C=v),T=2*l-T,C=2*v-C,l+=w[1],v+=w[2],e.quadraticCurveTo(T,C,l,v);break;case"z":case"Z":e.closePath();break;case"AC":l=w[1],v=w[2],d=w[3],a=w[4],n=w[5],M=w[6],e.arc(l,v,d,a,n,M);break;case"AT":h=w[1],f=w[2],l=w[3],v=w[4],d=w[5],e.arcTo(h,f,l,v,d);break;case"R":l=w[1],v=w[2],p=w[3],g=w[4],e.rect(l,v,p,g)}q.x=l,q.y=v}}}"undefined"!=typeof window&&u(window),e.path2dPolyfill=u,e.parsePath=r,Object.defineProperty(e,"__esModule",{value:!0})}); | ||
//# sourceMappingURL=path2d-polyfill.js.map |
{ | ||
"name": "path2d-polyfill", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "Polyfills Path2D api for canvas rendering", | ||
@@ -5,0 +5,0 @@ "scripts": { |
# path2d-polyfill | ||
[![CircleCI](https://circleci.com/gh/nilzona/path2d-polyfill.svg?style=svg)](https://circleci.com/gh/nilzona/path2d-polyfill) | ||
@@ -4,0 +3,0 @@ Polyfills Path2D api for rendering SVG paths in canvas |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
27244
65