Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

path2d-polyfill

Package Overview
Dependencies
Maintainers
1
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

path2d-polyfill - npm Package Compare versions

Comparing version 3.0.1 to 3.1.0

2

dist/path2d-polyfill.min.js

@@ -1,1 +0,1 @@

(function(){"use strict";var M={a:7,c:6,h:1,l:2,m:2,q:4,s:4,t:2,v:1,z:0},H=/([astvzqmhlc])([^astvzqmhlc]*)/gi,V=/-?[0-9]*\.?[0-9]+(?:e[-+]?\d+)?/gi;function Z(a){const r=a.match(V);return r?r.map(Number):[]}function U(a){const r=[],t=String(a).trim();return t[0]!=="M"&&t[0]!=="m"||t.replace(H,(n,l,o)=>{const s=Z(o);let i=l.toLowerCase(),h=l;if(i==="m"&&s.length>2&&(r.push([h,...s.splice(0,2)]),i="l",h=h==="m"?"l":"L"),s.length<M[i])return"";for(r.push([h,...s.splice(0,M[i])]);s.length>=M[i]&&s.length&&M[i];)r.push([h,...s.splice(0,M[i])]);return""}),r}function N(a,r){const t=a.x*Math.cos(r)-a.y*Math.sin(r),n=a.y*Math.cos(r)+a.x*Math.sin(r);a.x=t,a.y=n}function j(a,r,t){a.x+=r,a.y+=t}function S(a,r){a.x*=r,a.y*=r}var C=class L{constructor(r){this.commands=[],r&&r instanceof L?this.commands.push(...r.commands):r&&(this.commands=U(r))}addPath(r){r&&r instanceof L&&this.commands.push(...r.commands)}moveTo(r,t){this.commands.push(["M",r,t])}lineTo(r,t){this.commands.push(["L",r,t])}arc(r,t,n,l,o,s){this.commands.push(["AC",r,t,n,l,o,!!s])}arcTo(r,t,n,l,o){this.commands.push(["AT",r,t,n,l,o])}ellipse(r,t,n,l,o,s,i,h){this.commands.push(["E",r,t,n,l,o,s,i,!!h])}closePath(){this.commands.push(["Z"])}bezierCurveTo(r,t,n,l,o,s){this.commands.push(["C",r,t,n,l,o,s])}quadraticCurveTo(r,t,n,l){this.commands.push(["Q",r,t,n,l])}rect(r,t,n,l){this.commands.push(["R",r,t,n,l])}roundRect(r,t,n,l,o){typeof o>"u"?this.commands.push(["RR",r,t,n,l,0]):this.commands.push(["RR",r,t,n,l,o])}};function I(a,r){let t=0,n=0,l,o,s,i,h,u,P,v,F,k,Q,B,q,f,p,A,z,m,R,E,D,T=null,b=null,d=null,y=null,w=null,g=null;a.beginPath();for(let c=0;c<r.length;++c){m=r[c][0],m!=="S"&&m!=="s"&&m!=="C"&&m!=="c"&&(T=null,b=null),m!=="T"&&m!=="t"&&m!=="Q"&&m!=="q"&&(d=null,y=null);let e;switch(m){case"m":case"M":e=r[c],m==="m"?(t+=e[1],n+=e[2]):(t=e[1],n=e[2]),(m==="M"||!w)&&(w={x:t,y:n}),a.moveTo(t,n);break;case"l":e=r[c],t+=e[1],n+=e[2],a.lineTo(t,n);break;case"L":e=r[c],t=e[1],n=e[2],a.lineTo(t,n);break;case"H":e=r[c],t=e[1],a.lineTo(t,n);break;case"h":e=r[c],t+=e[1],a.lineTo(t,n);break;case"V":e=r[c],n=e[1],a.lineTo(t,n);break;case"v":e=r[c],n+=e[1],a.lineTo(t,n);break;case"a":case"A":if(e=r[c],g===null)throw new Error("This should never happen");m==="a"?(t+=e[6],n+=e[7]):(t=e[6],n=e[7]),f=e[1],p=e[2],P=e[3]*Math.PI/180,s=!!e[4],i=!!e[5],h={x:t,y:n},u={x:(g.x-h.x)/2,y:(g.y-h.y)/2},N(u,-P),v=u.x*u.x/(f*f)+u.y*u.y/(p*p),v>1&&(v=Math.sqrt(v),f*=v,p*=v),R={x:f*u.y/p,y:-(p*u.x)/f},F=f*f*p*p,k=f*f*u.y*u.y+p*p*u.x*u.x,i!==s?S(R,Math.sqrt((F-k)/k)||0):S(R,-Math.sqrt((F-k)/k)||0),o=Math.atan2((u.y-R.y)/p,(u.x-R.x)/f),l=Math.atan2(-(u.y+R.y)/p,-(u.x+R.x)/f),N(R,P),j(R,(h.x+g.x)/2,(h.y+g.y)/2),a.save(),a.translate(R.x,R.y),a.rotate(P),a.scale(f,p),a.arc(0,0,1,o,l,!i),a.restore();break;case"C":e=r[c],T=e[3],b=e[4],t=e[5],n=e[6],a.bezierCurveTo(e[1],e[2],T,b,t,n);break;case"c":e=r[c],a.bezierCurveTo(e[1]+t,e[2]+n,e[3]+t,e[4]+n,e[5]+t,e[6]+n),T=e[3]+t,b=e[4]+n,t+=e[5],n+=e[6];break;case"S":e=r[c],(T===null||b===null)&&(T=t,b=n),a.bezierCurveTo(2*t-T,2*n-b,e[1],e[2],e[3],e[4]),T=e[1],b=e[2],t=e[3],n=e[4];break;case"s":e=r[c],(T===null||b===null)&&(T=t,b=n),a.bezierCurveTo(2*t-T,2*n-b,e[1]+t,e[2]+n,e[3]+t,e[4]+n),T=e[1]+t,b=e[2]+n,t+=e[3],n+=e[4];break;case"Q":e=r[c],d=e[1],y=e[2],t=e[3],n=e[4],a.quadraticCurveTo(d,y,t,n);break;case"q":e=r[c],d=e[1]+t,y=e[2]+n,t+=e[3],n+=e[4],a.quadraticCurveTo(d,y,t,n);break;case"T":e=r[c],(d===null||y===null)&&(d=t,y=n),d=2*t-d,y=2*n-y,t=e[1],n=e[2],a.quadraticCurveTo(d,y,t,n);break;case"t":e=r[c],(d===null||y===null)&&(d=t,y=n),d=2*t-d,y=2*n-y,t+=e[1],n+=e[2],a.quadraticCurveTo(d,y,t,n);break;case"z":case"Z":w&&(t=w.x,n=w.y),w=null,a.closePath();break;case"AC":e=r[c],t=e[1],n=e[2],q=e[3],o=e[4],l=e[5],E=e[6],a.arc(t,n,q,o,l,E);break;case"AT":e=r[c],Q=e[1],B=e[2],t=e[3],n=e[4],q=e[5],a.arcTo(Q,B,t,n,q);break;case"E":e=r[c],t=e[1],n=e[2],f=e[3],p=e[4],P=e[5],o=e[6],l=e[7],E=e[8],a.save(),a.translate(t,n),a.rotate(P),a.scale(f,p),a.arc(0,0,1,o,l,E),a.restore();break;case"R":e=r[c],t=e[1],n=e[2],A=e[3],z=e[4],w={x:t,y:n},a.rect(t,n,A,z);break;case"RR":e=r[c],t=e[1],n=e[2],A=e[3],z=e[4],D=e[5],w={x:t,y:n},a.roundRect(t,n,A,z,D);break;default:throw new Error("Invalid path command: ".concat(m))}g?(g.x=t,g.y=n):g={x:t,y:n}}}function G(a,r,t,n){let l=arguments.length>4&&arguments[4]!==void 0?arguments[4]:0;if(typeof l=="number"&&(l=[l]),Array.isArray(l)){if(l.length===0||l.length>4)throw new RangeError("Failed to execute 'roundRect' on '".concat(this.constructor.name,"': ").concat(l.length," radii provided. Between one and four radii are necessary."));l.forEach(P=>{if(P<0)throw new RangeError("Failed to execute 'roundRect' on '".concat(this.constructor.name,"': Radius value ").concat(P," is negative."))})}else return;if(l.length===1&&l[0]===0){this.rect(a,r,t,n);return}const o=Math.min(t,n)/2,s=Math.min(o,l[0]);let i=s,h=s,u=s;l.length===2&&(i=Math.min(o,l[1]),u=i),l.length===3&&(i=Math.min(o,l[1]),u=i,h=Math.min(o,l[2])),l.length===4&&(i=Math.min(o,l[1]),h=Math.min(o,l[2]),u=Math.min(o,l[3])),this.moveTo(a,r+n-u),this.arcTo(a,r,a+s,r,s),this.arcTo(a+t,r,a+t,r+i,i),this.arcTo(a+t,r+n,a+t-h,r+n,h),this.arcTo(a,r+n,a,r+n-u,u),this.moveTo(a,r)}function J(a){if(!a)return;const r=a.prototype.fill,t=a.prototype.stroke,n=a.prototype.isPointInPath;a.prototype.fill=function(){if((arguments.length<=0?void 0:arguments[0])instanceof C){const s=arguments.length<=0?void 0:arguments[0],i=(arguments.length<=1?void 0:arguments[1])||"nonzero";return I(this,s.commands),r.apply(this,[i])}const o=(arguments.length<=0?void 0:arguments[0])||"nonzero";return r.apply(this,[o])},a.prototype.stroke=function(o){o&&I(this,o.commands),t.apply(this)},a.prototype.isPointInPath=function(){for(var o=arguments.length,s=new Array(o),i=0;i<o;i++)s[i]=arguments[i];if(s[0]instanceof C){const h=s[0],u=s[1],P=s[2],v=s[3]||"nonzero";return I(this,h.commands),n.apply(this,[u,P,v])}return n.apply(this,s)}}function K(a){a&&!a.prototype.roundRect&&(a.prototype.roundRect=G)}function O(a){a&&!a.prototype.roundRect&&(a.prototype.roundRect=G)}function W(){window&&(window.CanvasRenderingContext2D&&!window.Path2D&&(window.Path2D=C,J(window.CanvasRenderingContext2D)),O(window.Path2D),K(window.CanvasRenderingContext2D))}W()})();
(function(){"use strict";var M={a:7,c:6,h:1,l:2,m:2,q:4,s:4,t:2,v:1,z:0},V=/([astvzqmhlc])([^astvzqmhlc]*)/gi,Z=/-?[0-9]*\.?[0-9]+(?:e[-+]?\d+)?/gi;function U(a){const r=a.match(Z);return r?r.map(Number):[]}function j(a){const r=[],t=String(a).trim();return t[0]!=="M"&&t[0]!=="m"||t.replace(V,(n,l,i)=>{const o=U(i);let s=l.toLowerCase(),u=l;if(s==="m"&&o.length>2&&(r.push([u,...o.splice(0,2)]),s="l",u=u==="m"?"l":"L"),o.length<M[s])return"";for(r.push([u,...o.splice(0,M[s])]);o.length>=M[s]&&o.length&&M[s];)r.push([u,...o.splice(0,M[s])]);return""}),r}function N(a,r){const t=a.x*Math.cos(r)-a.y*Math.sin(r),n=a.y*Math.cos(r)+a.x*Math.sin(r);a.x=t,a.y=n}function D(a,r,t){a.x+=r,a.y+=t}function S(a,r){a.x*=r,a.y*=r}var z=class L{constructor(r){this.commands=[],r&&r instanceof L?this.commands.push(...r.commands):r&&(this.commands=j(r))}addPath(r){r&&r instanceof L&&this.commands.push(...r.commands)}moveTo(r,t){this.commands.push(["M",r,t])}lineTo(r,t){this.commands.push(["L",r,t])}arc(r,t,n,l,i,o){this.commands.push(["AC",r,t,n,l,i,!!o])}arcTo(r,t,n,l,i){this.commands.push(["AT",r,t,n,l,i])}ellipse(r,t,n,l,i,o,s,u){this.commands.push(["E",r,t,n,l,i,o,s,!!u])}closePath(){this.commands.push(["Z"])}bezierCurveTo(r,t,n,l,i,o){this.commands.push(["C",r,t,n,l,i,o])}quadraticCurveTo(r,t,n,l){this.commands.push(["Q",r,t,n,l])}rect(r,t,n,l){this.commands.push(["R",r,t,n,l])}roundRect(r,t,n,l,i){typeof i>"u"?this.commands.push(["RR",r,t,n,l,0]):this.commands.push(["RR",r,t,n,l,i])}};function A(a,r){let t=0,n=0,l,i,o,s,u,c,b,v,k,q,Q,B,E,f,p,C,I,y,P,F,H,T=null,g=null,d=null,m=null,w=null,R=null;a.beginPath();for(let h=0;h<r.length;++h){y=r[h][0],y!=="S"&&y!=="s"&&y!=="C"&&y!=="c"&&(T=null,g=null),y!=="T"&&y!=="t"&&y!=="Q"&&y!=="q"&&(d=null,m=null);let e;switch(y){case"m":case"M":e=r[h],y==="m"?(t+=e[1],n+=e[2]):(t=e[1],n=e[2]),(y==="M"||!w)&&(w={x:t,y:n}),a.moveTo(t,n);break;case"l":e=r[h],t+=e[1],n+=e[2],a.lineTo(t,n);break;case"L":e=r[h],t=e[1],n=e[2],a.lineTo(t,n);break;case"H":e=r[h],t=e[1],a.lineTo(t,n);break;case"h":e=r[h],t+=e[1],a.lineTo(t,n);break;case"V":e=r[h],n=e[1],a.lineTo(t,n);break;case"v":e=r[h],n+=e[1],a.lineTo(t,n);break;case"a":case"A":if(e=r[h],R===null)throw new Error("This should never happen");y==="a"?(t+=e[6],n+=e[7]):(t=e[6],n=e[7]),f=e[1],p=e[2],b=e[3]*Math.PI/180,o=!!e[4],s=!!e[5],u={x:t,y:n},c={x:(R.x-u.x)/2,y:(R.y-u.y)/2},N(c,-b),v=c.x*c.x/(f*f)+c.y*c.y/(p*p),v>1&&(v=Math.sqrt(v),f*=v,p*=v),P={x:f*c.y/p,y:-(p*c.x)/f},k=f*f*p*p,q=f*f*c.y*c.y+p*p*c.x*c.x,s!==o?S(P,Math.sqrt((k-q)/q)||0):S(P,-Math.sqrt((k-q)/q)||0),i=Math.atan2((c.y-P.y)/p,(c.x-P.x)/f),l=Math.atan2(-(c.y+P.y)/p,-(c.x+P.x)/f),N(P,b),D(P,(u.x+R.x)/2,(u.y+R.y)/2),a.save(),a.translate(P.x,P.y),a.rotate(b),a.scale(f,p),a.arc(0,0,1,i,l,!s),a.restore();break;case"C":e=r[h],T=e[3],g=e[4],t=e[5],n=e[6],a.bezierCurveTo(e[1],e[2],T,g,t,n);break;case"c":e=r[h],a.bezierCurveTo(e[1]+t,e[2]+n,e[3]+t,e[4]+n,e[5]+t,e[6]+n),T=e[3]+t,g=e[4]+n,t+=e[5],n+=e[6];break;case"S":e=r[h],(T===null||g===null)&&(T=t,g=n),a.bezierCurveTo(2*t-T,2*n-g,e[1],e[2],e[3],e[4]),T=e[1],g=e[2],t=e[3],n=e[4];break;case"s":e=r[h],(T===null||g===null)&&(T=t,g=n),a.bezierCurveTo(2*t-T,2*n-g,e[1]+t,e[2]+n,e[3]+t,e[4]+n),T=e[1]+t,g=e[2]+n,t+=e[3],n+=e[4];break;case"Q":e=r[h],d=e[1],m=e[2],t=e[3],n=e[4],a.quadraticCurveTo(d,m,t,n);break;case"q":e=r[h],d=e[1]+t,m=e[2]+n,t+=e[3],n+=e[4],a.quadraticCurveTo(d,m,t,n);break;case"T":e=r[h],(d===null||m===null)&&(d=t,m=n),d=2*t-d,m=2*n-m,t=e[1],n=e[2],a.quadraticCurveTo(d,m,t,n);break;case"t":e=r[h],(d===null||m===null)&&(d=t,m=n),d=2*t-d,m=2*n-m,t+=e[1],n+=e[2],a.quadraticCurveTo(d,m,t,n);break;case"z":case"Z":w&&(t=w.x,n=w.y),w=null,a.closePath();break;case"AC":e=r[h],t=e[1],n=e[2],E=e[3],i=e[4],l=e[5],F=e[6],a.arc(t,n,E,i,l,F);break;case"AT":e=r[h],Q=e[1],B=e[2],t=e[3],n=e[4],E=e[5],a.arcTo(Q,B,t,n,E);break;case"E":e=r[h],t=e[1],n=e[2],f=e[3],p=e[4],b=e[5],i=e[6],l=e[7],F=e[8],a.save(),a.translate(t,n),a.rotate(b),a.scale(f,p),a.arc(0,0,1,i,l,F),a.restore();break;case"R":e=r[h],t=e[1],n=e[2],C=e[3],I=e[4],w={x:t,y:n},a.rect(t,n,C,I);break;case"RR":e=r[h],t=e[1],n=e[2],C=e[3],I=e[4],H=e[5],w={x:t,y:n},a.roundRect(t,n,C,I,H);break;default:throw new Error("Invalid path command: ".concat(y))}R?(R.x=t,R.y=n):R={x:t,y:n}}}function G(a,r,t,n){let l=arguments.length>4&&arguments[4]!==void 0?arguments[4]:0;if(typeof l=="number"&&(l=[l]),Array.isArray(l)){if(l.length===0||l.length>4)throw new RangeError("Failed to execute 'roundRect' on '".concat(this.constructor.name,"': ").concat(l.length," radii provided. Between one and four radii are necessary."));l.forEach(b=>{if(b<0)throw new RangeError("Failed to execute 'roundRect' on '".concat(this.constructor.name,"': Radius value ").concat(b," is negative."))})}else return;if(l.length===1&&l[0]===0){this.rect(a,r,t,n);return}const i=Math.min(t,n)/2,o=Math.min(i,l[0]);let s=o,u=o,c=o;l.length===2&&(s=Math.min(i,l[1]),c=s),l.length===3&&(s=Math.min(i,l[1]),c=s,u=Math.min(i,l[2])),l.length===4&&(s=Math.min(i,l[1]),u=Math.min(i,l[2]),c=Math.min(i,l[3])),this.moveTo(a,r+n-c),this.arcTo(a,r,a+o,r,o),this.arcTo(a+t,r,a+t,r+s,s),this.arcTo(a+t,r+n,a+t-u,r+n,u),this.arcTo(a,r+n,a,r+n-c,c),this.moveTo(a,r)}function J(a){if(!a)return;const r=a.prototype.clip,t=a.prototype.fill,n=a.prototype.stroke,l=a.prototype.isPointInPath;a.prototype.clip=function(){if((arguments.length<=0?void 0:arguments[0])instanceof z){const s=arguments.length<=0?void 0:arguments[0],u=(arguments.length<=1?void 0:arguments[1])||"nonzero";return A(this,s.commands),r.apply(this,[u])}const o=(arguments.length<=0?void 0:arguments[0])||"nonzero";return r.apply(this,[o])},a.prototype.fill=function(){if((arguments.length<=0?void 0:arguments[0])instanceof z){const s=arguments.length<=0?void 0:arguments[0],u=(arguments.length<=1?void 0:arguments[1])||"nonzero";return A(this,s.commands),t.apply(this,[u])}const o=(arguments.length<=0?void 0:arguments[0])||"nonzero";return t.apply(this,[o])},a.prototype.stroke=function(o){o&&A(this,o.commands),n.apply(this)},a.prototype.isPointInPath=function(){for(var o=arguments.length,s=new Array(o),u=0;u<o;u++)s[u]=arguments[u];if(s[0]instanceof z){const c=s[0],b=s[1],v=s[2],k=s[3]||"nonzero";return A(this,c.commands),l.apply(this,[b,v,k])}return l.apply(this,s)}}function K(a){a&&!a.prototype.roundRect&&(a.prototype.roundRect=G)}function O(a){a&&!a.prototype.roundRect&&(a.prototype.roundRect=G)}function W(){window&&(window.CanvasRenderingContext2D&&!window.Path2D&&(window.Path2D=z,J(window.CanvasRenderingContext2D)),O(window.Path2D),K(window.CanvasRenderingContext2D))}W()})();
{
"name": "path2d-polyfill",
"version": "3.0.1",
"version": "3.1.0",
"description": "Polyfills Path2D api for canvas rendering",

@@ -37,8 +37,8 @@ "keywords": [

"dependencies": {
"path2d": "0.1.2"
"path2d": "0.2.0"
},
"devDependencies": {
"@babel/core": "7.24.0",
"@babel/preset-env": "7.24.0",
"@qlik/eslint-config": "0.7.13",
"@babel/core": "7.24.3",
"@babel/preset-env": "7.24.3",
"@qlik/eslint-config": "0.7.15",
"@qlik/prettier-config": "0.4.11",

@@ -51,4 +51,4 @@ "@qlik/tsconfig": "0.2.4",

"prettier": "3.2.5",
"typescript": "5.4.2",
"vite": "5.1.6",
"typescript": "5.4.3",
"vite": "5.2.7",
"vitest": "1.4.0"

@@ -55,0 +55,0 @@ },

# path2d-polyfill
[![validate](https://github.com/nilzona/path2d-polyfill/actions/workflows/validate.yaml/badge.svg)](https://github.com/nilzona/path2d-polyfill/actions/workflows/validate.yaml)
[![CI](https://github.com/nilzona/path2d-polyfill/actions/workflows/ci.yml/badge.svg)](https://github.com/nilzona/path2d-polyfill/actions/workflows/ci.yml)

@@ -5,0 +5,0 @@ Polyfills `Path2D` api and `roundRect` for CanvasRenderingContext2D

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc