Socket
Socket
Sign inDemoInstall

path2d-polyfill

Package Overview
Dependencies
1
Maintainers
1
Versions
35
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.0.1 to 2.1.1

2

dist/path2d-polyfill.min.js

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

!function(){"use strict";function t(t,e,n){if(n||2===arguments.length)for(var a,o=0,r=e.length;o<r;o++)!a&&o in e||(a||(a=Array.prototype.slice.call(e,0,o)),a[o]=e[o]);return t.concat(a||Array.prototype.slice.call(e))}var e={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 o(o){var r=[],s=String(o).trim();return"M"!==s[0]&&"m"!==s[0]||s.replace(n,(function(n,o,s){var c=function(t){var e=t.match(a);return e?e.map(Number):[]}(s),i=o.toLowerCase(),u=o;if("m"===i&&c.length>2&&(r.push(t([u],c.splice(0,2),!0)),i="l",u="m"===u?"l":"L"),c.length<e[i])return"";for(r.push(t([u],c.splice(0,e[i]),!0));c.length>=e[i]&&c.length&&e[i];)r.push(t([u],c.splice(0,e[i]),!0));return""})),r}function r(t,e){var n=t.x*Math.cos(e)-t.y*Math.sin(e),a=t.y*Math.cos(e)+t.x*Math.sin(e);t.x=n,t.y=a}function s(t,e){t.x*=e,t.y*=e}var c=function(){function t(e){var n;this.commands=[],e&&e instanceof t?(n=this.commands).push.apply(n,e.commands):e&&(this.commands=o(e))}return t.prototype.addPath=function(e){var n;e&&e instanceof t&&(n=this.commands).push.apply(n,e.commands)},t.prototype.moveTo=function(t,e){this.commands.push(["M",t,e])},t.prototype.lineTo=function(t,e){this.commands.push(["L",t,e])},t.prototype.arc=function(t,e,n,a,o,r){this.commands.push(["AC",t,e,n,a,o,!!r])},t.prototype.arcTo=function(t,e,n,a,o){this.commands.push(["AT",t,e,n,a,o])},t.prototype.ellipse=function(t,e,n,a,o,r,s,c){this.commands.push(["E",t,e,n,a,o,r,s,!!c])},t.prototype.closePath=function(){this.commands.push(["Z"])},t.prototype.bezierCurveTo=function(t,e,n,a,o,r){this.commands.push(["C",t,e,n,a,o,r])},t.prototype.quadraticCurveTo=function(t,e,n,a){this.commands.push(["Q",t,e,n,a])},t.prototype.rect=function(t,e,n,a){this.commands.push(["R",t,e,n,a])},t.prototype.roundRect=function(t,e,n,a,o){void 0===o?this.commands.push(["RR",t,e,n,a,0]):this.commands.push(["RR",t,e,n,a,o])},t}();function i(t,e){var n,a,o,c,i,u,h,l,p,m,y,d,f,v,x,T,b,g,C,k,R,M,q,w,z=0,P=0,A=null,D=null,E=null,L=null,I=null,Q=null;t.beginPath();for(var S=0;S<e.length;++S){"S"!==(g=e[S][0])&&"s"!==g&&"C"!==g&&"c"!==g&&(A=null,D=null),"T"!==g&&"t"!==g&&"Q"!==g&&"q"!==g&&(E=null,L=null);var F=void 0;switch(g){case"m":case"M":F=e[S],"m"===g?(z+=F[1],P+=F[2]):(z=F[1],P=F[2]),"M"!==g&&I||(I={x:z,y:P}),t.moveTo(z,P);break;case"l":z+=(F=e[S])[1],P+=F[2],t.lineTo(z,P);break;case"L":z=(F=e[S])[1],P=F[2],t.lineTo(z,P);break;case"H":z=(F=e[S])[1],t.lineTo(z,P);break;case"h":z+=(F=e[S])[1],t.lineTo(z,P);break;case"V":P=(F=e[S])[1],t.lineTo(z,P);break;case"v":P+=(F=e[S])[1],t.lineTo(z,P);break;case"a":case"A":if(F=e[S],null===Q)throw new Error("This should never happen");"a"===g?(z+=F[6],P+=F[7]):(z=F[6],P=F[7]),v=F[1],x=F[2],h=F[3]*Math.PI/180,o=!!F[4],c=!!F[5],i={x:z,y:P},r(u={x:(Q.x-i.x)/2,y:(Q.y-i.y)/2},-h),(l=u.x*u.x/(v*v)+u.y*u.y/(x*x))>1&&(v*=l=Math.sqrt(l),x*=l),p=v*v*x*x,m=v*v*u.y*u.y+x*x*u.x*u.x,s(C={x:v*u.y/x,y:-x*u.x/v},c!==o?Math.sqrt((p-m)/m)||0:-Math.sqrt((p-m)/m)||0),a=Math.atan2((u.y-C.y)/x,(u.x-C.x)/v),n=Math.atan2(-(u.y+C.y)/x,-(u.x+C.x)/v),r(C,h),M=C,q=(i.x+Q.x)/2,w=(i.y+Q.y)/2,M.x+=q,M.y+=w,t.save(),t.translate(C.x,C.y),t.rotate(h),t.scale(v,x),t.arc(0,0,1,a,n,!c),t.restore();break;case"C":A=(F=e[S])[3],D=F[4],z=F[5],P=F[6],t.bezierCurveTo(F[1],F[2],A,D,z,P);break;case"c":F=e[S],t.bezierCurveTo(F[1]+z,F[2]+P,F[3]+z,F[4]+P,F[5]+z,F[6]+P),A=F[3]+z,D=F[4]+P,z+=F[5],P+=F[6];break;case"S":F=e[S],null!==A&&null!==D||(A=z,D=P),t.bezierCurveTo(2*z-A,2*P-D,F[1],F[2],F[3],F[4]),A=F[1],D=F[2],z=F[3],P=F[4];break;case"s":F=e[S],null!==A&&null!==D||(A=z,D=P),t.bezierCurveTo(2*z-A,2*P-D,F[1]+z,F[2]+P,F[3]+z,F[4]+P),A=F[1]+z,D=F[2]+P,z+=F[3],P+=F[4];break;case"Q":E=(F=e[S])[1],L=F[2],z=F[3],P=F[4],t.quadraticCurveTo(E,L,z,P);break;case"q":E=(F=e[S])[1]+z,L=F[2]+P,z+=F[3],P+=F[4],t.quadraticCurveTo(E,L,z,P);break;case"T":null!==E&&null!==L||(E=z,L=P),E=2*z-E,L=2*P-L,z=(F=e[S])[1],P=F[2],t.quadraticCurveTo(E,L,z,P);break;case"t":null!==E&&null!==L||(E=z,L=P),E=2*z-E,L=2*P-L,z+=(F=e[S])[1],P+=F[2],t.quadraticCurveTo(E,L,z,P);break;case"z":case"Z":I&&(z=I.x,P=I.y),I=null,t.closePath();break;case"AC":z=(F=e[S])[1],P=F[2],f=F[3],a=F[4],n=F[5],k=F[6],t.arc(z,P,f,a,n,k);break;case"AT":y=(F=e[S])[1],d=F[2],z=F[3],P=F[4],f=F[5],t.arcTo(y,d,z,P,f);break;case"E":z=(F=e[S])[1],P=F[2],v=F[3],x=F[4],h=F[5],a=F[6],n=F[7],k=F[8],t.save(),t.translate(z,P),t.rotate(h),t.scale(v,x),t.arc(0,0,1,a,n,k),t.restore();break;case"R":z=(F=e[S])[1],P=F[2],T=F[3],b=F[4],I={x:z,y:P},t.rect(z,P,T,b);break;case"RR":z=(F=e[S])[1],P=F[2],T=F[3],b=F[4],R=F[5],I={x:z,y:P},t.roundRect(z,P,T,b,R)}Q?(Q.x=z,Q.y=P):Q={x:z,y:P}}}function u(t,e,n,a,o){var r=this;if(void 0===o&&(o=0),"number"==typeof o&&(o=[o]),Array.isArray(o)){if(0===o.length||o.length>4)throw new RangeError("Failed to execute 'roundRect' on '".concat(this.constructor.name,"': ").concat(o.length," radii provided. Between one and four radii are necessary."));if(o.forEach((function(t){if(t<0)throw new RangeError("Failed to execute 'roundRect' on '".concat(r.constructor.name,"': Radius value ").concat(t," is negative."))})),1===o.length&&0===o[0])return this.rect(t,e,n,a);var s,c,i,u=Math.min(n,a)/2,h=s=c=i=Math.min(u,o[0]);2===o.length&&(s=i=Math.min(u,o[1])),3===o.length&&(s=i=Math.min(u,o[1]),c=Math.min(u,o[2])),4===o.length&&(s=Math.min(u,o[1]),c=Math.min(u,o[2]),i=Math.min(u,o[3])),this.moveTo(t,e+a-i),this.arcTo(t,e,t+h,e,h),this.arcTo(t+n,e,t+n,e+s,s),this.arcTo(t+n,e+a,t+n-c,e+a,c),this.arcTo(t,e+a,t,e+a-i,i),this.moveTo(t,e)}}!function(t){if(t&&t.CanvasRenderingContext2D&&!t.Path2D){var e=t.CanvasRenderingContext2D,n=e.prototype.fill,a=e.prototype.stroke,o=e.prototype.isPointInPath;e.prototype.fill=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];if(!(t[0]instanceof c)){o=t[0]||"nonzero";return n.apply(this,[o])}var a=t[0],o=t[1]||"nonzero";i(this,a.commands),n.apply(this,[o])},e.prototype.stroke=function(t){t&&i(this,t.commands),a.apply(this)},e.prototype.isPointInPath=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];if(t[0]instanceof c){var n=t[0],a=t[1],r=t[2],s=t[3]||"nonzero";return i(this,n.commands),o.apply(this,[a,r,s])}return o.apply(this,t)},t.Path2D=c}}(window),function(t){if(t&&t.CanvasRenderingContext2D){var e=t.CanvasRenderingContext2D,n=t.Path2D;e&&!e.prototype.roundRect&&(e.prototype.roundRect=u),n&&!n.prototype.roundRect&&(n.prototype.roundRect=u)}}(window)}();
(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()})();
{
"name": "path2d-polyfill",
"version": "2.0.1",
"version": "2.1.1",
"description": "Polyfills Path2D api for canvas rendering",
"scripts": {
"build": "rm -rf dist/* && rollup -c",
"start": "rollup -c -w",
"lint": "eslint .",
"check-types": "tsc --noEmit",
"test": "ts-mocha test/*.spec.ts",
"test:watch": "ts-mocha --watch test/*.spec.ts",
"test:coverage": "nyc --reporter=html --reporter=text --reporter=text-summary yarn test",
"format:check": "prettier --check \"./**\"",
"format:write": "prettier --write \"./**\"",
"prepare": "husky install",
"release": "release-it"
},
"main": "dist/path2d-node.cjs",
"browser": "dist/path2d-polyfill.min.js",
"exports": {
"node": {
"import": "./dist/path2d-node.mjs",
"require": "./dist/path2d-node.cjs"
},
"development": "./dist/path2d-polyfill.dev.js",
"module": "./dist/path2d-polyfill.esm.js",
"default": "./dist/path2d-polyfill.min.js"
},
"files": [
"dist"
],
"repository": {
"type": "git",
"url": "git+https://github.com/nilzona/path2d-polyfill.git"
},
"keywords": [

@@ -42,41 +11,63 @@ "Path2D",

],
"author": "nilzona",
"license": "MIT",
"homepage": "https://github.com/nilzona/path2d-polyfill#readme",
"bugs": {
"url": "https://github.com/nilzona/path2d-polyfill/issues"
},
"homepage": "https://github.com/nilzona/path2d-polyfill#readme",
"repository": {
"type": "git",
"url": "git+https://github.com/nilzona/path2d-polyfill.git"
},
"license": "MIT",
"author": "nilzona",
"type": "module",
"exports": {
"browser": "./dist/path2d-polyfill.min.js"
},
"browser": "dist/path2d-polyfill.min.js",
"files": [
"dist"
],
"browserslist": [
">0.1%",
"ie >= 11",
"last 2 versions",
"not dead"
],
"prettier": "@qlik/prettier-config",
"dependencies": {
"path2d": "0.1.1"
},
"devDependencies": {
"@commitlint/cli": "17.3.0",
"@commitlint/config-conventional": "17.3.0",
"@release-it/conventional-changelog": "5.1.1",
"@rollup/plugin-terser": "0.2.1",
"@rollup/plugin-typescript": "10.0.1",
"@types/chai": "^4.3.4",
"@types/mocha": "^10.0.1",
"@types/sinon": "^10.0.13",
"@types/sinon-chai": "^3.2.9",
"@typescript-eslint/eslint-plugin": "5.48.0",
"@typescript-eslint/parser": "5.48.0",
"chai": "4.3.7",
"eslint": "8.31.0",
"eslint-config-prettier": "8.6.0",
"husky": "8.0.2",
"lint-staged": "13.1.0",
"mocha": "10.2.0",
"nyc": "15.1.0",
"prettier": "2.8.1",
"release-it": "15.6.0",
"rollup": "3.9.1",
"rollup-plugin-livereload": "2.0.5",
"rollup-plugin-serve": "2.0.2",
"sinon": "15.0.1",
"sinon-chai": "3.7.0",
"ts-mocha": "^10.0.0",
"typescript": "^4.9.4"
"@babel/core": "7.24.0",
"@babel/preset-env": "7.24.0",
"@qlik/eslint-config": "0.7.13",
"@qlik/prettier-config": "0.4.11",
"@qlik/tsconfig": "0.2.4",
"@rollup/plugin-babel": "6.0.4",
"@vitest/coverage-v8": "1.4.0",
"eslint": "8.57.0",
"jsdom": "24.0.0",
"prettier": "3.2.5",
"typescript": "5.4.2",
"vite": "5.1.6",
"vitest": "1.4.0"
},
"dependencies": {},
"engines": {
"node": ">=8"
"node": ">=18"
},
"publishConfig": {
"access": "public"
},
"scripts": {
"build": "vite build && cp dist/path2d-polyfill.min.js test/path2d-polyfill.min.js",
"check-types": "tsc --noEmit",
"dev": "vite",
"format:check": "prettier --check '**' --ignore-unknown",
"format:write": "prettier --write '**' --ignore-unknown",
"lint": "eslint .",
"preview": "vite preview",
"test": "vitest run",
"test:coverage": "vitest run --coverage",
"test:watch": "vitest"
}
}
}

@@ -15,14 +15,2 @@ # path2d-polyfill

or install from npm
```shell
npm install --save path2d-polyfill
```
and import with module bundler e.g. webpack _before_ using the feature
```javascript
import "path2d-polyfill";
```
This will polyfill the browser's window object with Path2D features and it will also polyfill roundRect if they are missing in both CanvasRenderingContexst and Path2D.

@@ -37,44 +25,2 @@

## Usage in a node environment
It is possible to use this library in a node environment as well. The package exports a few functions that can be used:
- `Path2D` - class to create Path2D objects used by the polyfill methods
- `polyfillPath2D` - function that adds Path2D to a "window like" object and polyfills CanvasRenderingContext2D to use Path2D
- `polyfillRoundRect` - polyfills roundRect function on Path2D and CanvasRenderingContext2D (missing in firefox)
- `parsePath` - function for parsing an SVG path string into canvas commands
use any of these functions like:
```js
const { polyfillRoundRect } = require "path2d-polyfill";
const windowlike = { CanvasRenderingContext2D, Path2D };
polyfillRoundRect(windowLike);
// roundRect functions has now been added if they were missing
```
### usage with node-canvas
To get Path2D features with the [node-canvas library](https://github.com/Automattic/node-canvas) use the following pattern:
```js
const { createCanvas, CanvasRenderingContext2D } = require("canvas");
const { polyfillPath2D } = require("path2d-polyfill/path2d");
global.CanvasRenderingContext2D = CanvasRenderingContext2D;
polyfillPath2D(global);
// Path2D has now been added to global object
const canvas = createCanvas(200, 200);
const ctx = canvas.getContext("2d");
const p = new Path2D("M10 10 l 20 0 l 0 20 Z");
ctx.fillStyle = "green";
ctx.fill(p);
```
A working example of a node express server that serves an image drawn with canvas can be seen [here](https://gist.github.com/nilzona/e611c99336d8ea1f645bd391a459c24f)
## Support table

@@ -98,10 +44,10 @@

Clone this repo and run the following
Clone [path2d-polyfill](https://github.com/nilzona/path2d-polyfill)
```shell
yarn
yarn start
pnpm install
pnpm dev
```
open <http://localhost:10001> to see the example page.
open <http://localhost:5173/> to see the example page.

@@ -108,0 +54,0 @@ ## Contributing

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc