-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathp5.svg.min.js
30 lines (28 loc) · 35.3 KB
/
p5.svg.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
!function(){"use strict";
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */var t=function(e,r){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])},t(e,r)};function e(t,e,r,i){return new(r||(r=Promise))((function(n,a){function o(t){try{l(i.next(t))}catch(t){a(t)}}function s(t){try{l(i.throw(t))}catch(t){a(t)}}function l(t){var e;t.done?n(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(o,s)}l((i=i.apply(t,e||[])).next())}))}function r(t,e){var r,i,n,a,o={label:0,sent:function(){if(1&n[0])throw n[1];return n[1]},trys:[],ops:[]};return a={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function s(a){return function(s){return function(a){if(r)throw new TypeError("Generator is already executing.");for(;o;)try{if(r=1,i&&(n=2&a[0]?i.return:a[0]?i.throw||((n=i.return)&&n.call(i),0):i.next)&&!(n=n.call(i,a[1])).done)return n;switch(i=0,n&&(a=[2&a[0],n.value]),a[0]){case 0:case 1:n=a;break;case 4:return o.label++,{value:a[1],done:!1};case 5:o.label++,i=a[1],a=[0];continue;case 7:a=o.ops.pop(),o.trys.pop();continue;default:if(!(n=o.trys,(n=n.length>0&&n[n.length-1])||6!==a[0]&&2!==a[0])){o=0;continue}if(3===a[0]&&(!n||a[1]>n[0]&&a[1]<n[3])){o.label=a[1];break}if(6===a[0]&&o.label<n[1]){o.label=n[1],n=a;break}if(n&&o.label<n[2]){o.label=n[2],o.ops.push(a);break}n[2]&&o.ops.pop(),o.trys.pop();continue}a=e.call(t,o)}catch(t){a=[6,t],i=0}finally{r=n=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,s])}}}var i=!1;function n(t){return t?"string"==typeof t?t:t+"":t}const a=new class{async svg2canvas(t,e,r){const i=await new Promise((e=>{var r=new Image;r.onload=function(){e(r)},r.src=t}));var n=document.createElement("canvas");n.width=e,n.height=r;return n.getContext("2d").drawImage(i,0,0),n}toDataURL(t,e,r,i,n,a){var o=(new XMLSerializer).serializeToString(t);if(document.documentMode){/xmlns="http:\/\/www\.w3\.org\/2000\/svg".+xmlns="http:\/\/www\.w3\.org\/2000\/svg/gi.test(o)&&(o=o.replace('xmlns="http://www.w3.org/2000/svg','xmlns:xlink="http://www.w3.org/1999/xlink'))}a||(a={});var s="data:image/svg+xml;charset=utf-8,"+encodeURIComponent(o);if("image/svg+xml"===i||!i)return a.async?Promise.resolve(s):s;if("image/jpeg"===i||"image/png"===i){if(!a.async)throw new Error("svgcanvas: options.async must be set to true if type is image/jpeg | image/png");return(async()=>{const t=await this.svg2canvas(s,e,r),a=t.toDataURL(i,n);return t.remove(),a})()}throw new Error("svgcanvas: Unknown type for toDataURL, please use image/jpeg | image/png | image/svg+xml.")}getImageData(t,e,r,i,n,a,o,s){if(s||(s={}),!s.async)throw new Error("svgcanvas: options.async must be set to true for getImageData");const l=this.toDataURL(t,e,r,"image/svg+xml");return(async()=>{const t=await this.svg2canvas(l,e,r),s=t.getContext("2d").getImageData(i,n,a,o);return t.remove(),s})()}};
/*!!
* SVGCanvas v2.0.3
* Draw on SVG using Canvas's 2D Context API.
*
* Licensed under the MIT license:
* http://www.opensource.org/licenses/mit-license.php
*
* Author:
* Kerry Liu
* Zeno Zeng
*
* Copyright (c) 2014 Gliffy Inc.
* Copyright (c) 2021 Zeno Zeng
*/var o=function(){var t,e,r,i,o;function s(t,e){var r,i=Object.keys(e);for(r=0;r<i.length;r++)t=t.replace(new RegExp("\\{"+i[r]+"\\}","gi"),e[i[r]]);return t}function l(t){var e,r,i;if(!t)throw new Error("cannot create a random attribute name for an undefined object");e="ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz",r="";do{for(r="",i=0;i<12;i++)r+=e[Math.floor(51*Math.random())]}while(t[r]);return r}function h(t){var e={alphabetic:"alphabetic",hanging:"hanging",top:"text-before-edge",bottom:"text-after-edge",middle:"central"};return e[t]||e.alphabetic}o=function(t,e){var r,i,n,a={};for(t=t.split(","),e=e||10,r=0;r<t.length;r+=2)i="&"+t[r+1]+";",n=parseInt(t[r],e),a[i]="&#"+n+";";return a["\\xa0"]=" ",a}("50,nbsp,51,iexcl,52,cent,53,pound,54,curren,55,yen,56,brvbar,57,sect,58,uml,59,copy,5a,ordf,5b,laquo,5c,not,5d,shy,5e,reg,5f,macr,5g,deg,5h,plusmn,5i,sup2,5j,sup3,5k,acute,5l,micro,5m,para,5n,middot,5o,cedil,5p,sup1,5q,ordm,5r,raquo,5s,frac14,5t,frac12,5u,frac34,5v,iquest,60,Agrave,61,Aacute,62,Acirc,63,Atilde,64,Auml,65,Aring,66,AElig,67,Ccedil,68,Egrave,69,Eacute,6a,Ecirc,6b,Euml,6c,Igrave,6d,Iacute,6e,Icirc,6f,Iuml,6g,ETH,6h,Ntilde,6i,Ograve,6j,Oacute,6k,Ocirc,6l,Otilde,6m,Ouml,6n,times,6o,Oslash,6p,Ugrave,6q,Uacute,6r,Ucirc,6s,Uuml,6t,Yacute,6u,THORN,6v,szlig,70,agrave,71,aacute,72,acirc,73,atilde,74,auml,75,aring,76,aelig,77,ccedil,78,egrave,79,eacute,7a,ecirc,7b,euml,7c,igrave,7d,iacute,7e,icirc,7f,iuml,7g,eth,7h,ntilde,7i,ograve,7j,oacute,7k,ocirc,7l,otilde,7m,ouml,7n,divide,7o,oslash,7p,ugrave,7q,uacute,7r,ucirc,7s,uuml,7t,yacute,7u,thorn,7v,yuml,ci,fnof,sh,Alpha,si,Beta,sj,Gamma,sk,Delta,sl,Epsilon,sm,Zeta,sn,Eta,so,Theta,sp,Iota,sq,Kappa,sr,Lambda,ss,Mu,st,Nu,su,Xi,sv,Omicron,t0,Pi,t1,Rho,t3,Sigma,t4,Tau,t5,Upsilon,t6,Phi,t7,Chi,t8,Psi,t9,Omega,th,alpha,ti,beta,tj,gamma,tk,delta,tl,epsilon,tm,zeta,tn,eta,to,theta,tp,iota,tq,kappa,tr,lambda,ts,mu,tt,nu,tu,xi,tv,omicron,u0,pi,u1,rho,u2,sigmaf,u3,sigma,u4,tau,u5,upsilon,u6,phi,u7,chi,u8,psi,u9,omega,uh,thetasym,ui,upsih,um,piv,812,bull,816,hellip,81i,prime,81j,Prime,81u,oline,824,frasl,88o,weierp,88h,image,88s,real,892,trade,89l,alefsym,8cg,larr,8ch,uarr,8ci,rarr,8cj,darr,8ck,harr,8dl,crarr,8eg,lArr,8eh,uArr,8ei,rArr,8ej,dArr,8ek,hArr,8g0,forall,8g2,part,8g3,exist,8g5,empty,8g7,nabla,8g8,isin,8g9,notin,8gb,ni,8gf,prod,8gh,sum,8gi,minus,8gn,lowast,8gq,radic,8gt,prop,8gu,infin,8h0,ang,8h7,and,8h8,or,8h9,cap,8ha,cup,8hb,int,8hk,there4,8hs,sim,8i5,cong,8i8,asymp,8j0,ne,8j1,equiv,8j4,le,8j5,ge,8k2,sub,8k3,sup,8k4,nsub,8k6,sube,8k7,supe,8kl,oplus,8kn,otimes,8l5,perp,8m5,sdot,8o8,lceil,8o9,rceil,8oa,lfloor,8ob,rfloor,8p9,lang,8pa,rang,9ea,loz,9j0,spades,9j3,clubs,9j5,hearts,9j6,diams,ai,OElig,aj,oelig,b0,Scaron,b1,scaron,bo,Yuml,m6,circ,ms,tilde,802,ensp,803,emsp,809,thinsp,80c,zwnj,80d,zwj,80e,lrm,80f,rlm,80j,ndash,80k,mdash,80o,lsquo,80p,rsquo,80q,sbquo,80s,ldquo,80t,rdquo,80u,bdquo,810,dagger,811,Dagger,81g,permil,81p,lsaquo,81q,rsaquo,85c,euro",32),t={strokeStyle:{svgAttr:"stroke",canvas:"#000000",svg:"none",apply:"stroke"},fillStyle:{svgAttr:"fill",canvas:"#000000",svg:null,apply:"fill"},lineCap:{svgAttr:"stroke-linecap",canvas:"butt",svg:"butt",apply:"stroke"},lineJoin:{svgAttr:"stroke-linejoin",canvas:"miter",svg:"miter",apply:"stroke"},miterLimit:{svgAttr:"stroke-miterlimit",canvas:10,svg:4,apply:"stroke"},lineWidth:{svgAttr:"stroke-width",canvas:1,svg:1,apply:"stroke"},globalAlpha:{svgAttr:"opacity",canvas:1,svg:1,apply:"fill stroke"},font:{canvas:"10px sans-serif"},shadowColor:{canvas:"#000000"},shadowOffsetX:{canvas:0},shadowOffsetY:{canvas:0},shadowBlur:{canvas:0},textAlign:{canvas:"start"},textBaseline:{canvas:"alphabetic"},lineDash:{svgAttr:"stroke-dasharray",canvas:[],svg:null,apply:"stroke"}},(r=function(t,e){this.__root=t,this.__ctx=e}).prototype.addColorStop=function(t,e){var r,i=this.__ctx.__createElement("stop");i.setAttribute("offset",t),-1!==n(e).indexOf("rgba")?(r=/rgba\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d?\.?\d*)\s*\)/gi.exec(e),i.setAttribute("stop-color",s("rgb({r},{g},{b})",{r:r[1],g:r[2],b:r[3]})),i.setAttribute("stop-opacity",r[4])):i.setAttribute("stop-color",n(e)),this.__root.appendChild(i)},i=function(t,e){this.__root=t,this.__ctx=e},e=function(t){var r,i={width:500,height:500,enableMirroring:!1};if(arguments.length>1?((r=i).width=t,r.height=arguments[1]):r=t||i,!(this instanceof e))return new e(r);this.width=r.width||i.width,this.height=r.height||i.height,this.enableMirroring=void 0!==r.enableMirroring?r.enableMirroring:i.enableMirroring,this.canvas=this,this.__document=r.document||document,r.ctx?this.__ctx=r.ctx:(this.__canvas=this.__document.createElement("canvas"),this.__ctx=this.__canvas.getContext("2d")),this.__setDefaultStyles(),this.__styleStack=[this.__getStyleState()],this.__groupStack=[],this.__root=this.__document.createElementNS("http://www.w3.org/2000/svg","svg"),this.__root.setAttribute("version",1.1),this.__root.setAttribute("xmlns","http://www.w3.org/2000/svg"),this.__root.setAttributeNS("http://www.w3.org/2000/xmlns/","xmlns:xlink","http://www.w3.org/1999/xlink"),this.__root.setAttribute("width",this.width),this.__root.setAttribute("height",this.height),this.__ids={},this.__defs=this.__document.createElementNS("http://www.w3.org/2000/svg","defs"),this.__root.appendChild(this.__defs),this.__currentElement=this.__document.createElementNS("http://www.w3.org/2000/svg","g"),this.__root.appendChild(this.__currentElement),this.resetTransform(),this.__options=r,this.__id=Math.random().toString(16).substring(2,8),this.__debug("new",t)},e.prototype.__debug=function(...t){this.__options.debug&&console.debug(`svgcanvas#${this.__id}:`,...t)},e.prototype.__createElement=function(t,e,r){void 0===e&&(e={});var i,n,a=this.__document.createElementNS("http://www.w3.org/2000/svg",t),o=Object.keys(e);for(r&&(a.setAttribute("fill","none"),a.setAttribute("stroke","none")),i=0;i<o.length;i++)n=o[i],a.setAttribute(n,e[n]);return a},e.prototype.__setDefaultStyles=function(){var e,r,i=Object.keys(t);for(e=0;e<i.length;e++)this[r=i[e]]=t[r].canvas},e.prototype.__applyStyleState=function(t){var e,r,i=Object.keys(t);for(e=0;e<i.length;e++)this[r=i[e]]=t[r]},e.prototype.__getStyleState=function(){var e,r,i={},n=Object.keys(t);for(e=0;e<n.length;e++)i[r=n[e]]=this[r];return i},e.prototype.__applyTransformation=function(t,e){const{a:r,b:i,c:n,d:a,e:o,f:s}=e||this.getTransform();t.setAttribute("transform",`matrix(${r} ${i} ${n} ${a} ${o} ${s})`)},e.prototype.__applyStyleToCurrentElement=function(e){var n=this.__currentElement,a=this.__currentElementsToStyle;a&&(n.setAttribute(e,""),n=a.element,a.children.forEach((function(t){t.setAttribute(e,"")})));var o,l,h,c,p,u,f,d=Object.keys(t);for(o=0;o<d.length;o++)if(l=t[d[o]],h=this[d[o]],l.apply)if(h instanceof i){if(h.__ctx)for(u=0;u<h.__ctx.__defs.childNodes.length;u++)p=(f=h.__ctx.__defs.childNodes[u]).getAttribute("id"),this.__ids[p]=p,this.__defs.appendChild(f);n.setAttribute(l.apply,s("url(#{id})",{id:h.__root.getAttribute("id")}))}else if(h instanceof r)n.setAttribute(l.apply,s("url(#{id})",{id:h.__root.getAttribute("id")}));else if(-1!==l.apply.indexOf(e)&&l.svg!==h)if("stroke"!==l.svgAttr&&"fill"!==l.svgAttr||-1===h.indexOf("rgba")){var _=l.svgAttr;if("globalAlpha"===d[o]&&(_=e+"-"+l.svgAttr,n.getAttribute(_)))continue;n.setAttribute(_,h)}else{c=/rgba\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d?\.?\d*)\s*\)/gi.exec(h),n.setAttribute(l.svgAttr,s("rgb({r},{g},{b})",{r:c[1],g:c[2],b:c[3]}));var g=c[4],m=this.globalAlpha;null!=m&&(g*=m),n.setAttribute(l.svgAttr+"-opacity",g)}},e.prototype.__closestGroupOrSvg=function(t){return"g"===(t=t||this.__currentElement).nodeName||"svg"===t.nodeName?t:this.__closestGroupOrSvg(t.parentNode)},e.prototype.getSerializedSvg=function(t){var e,r,i,n,a,s=(new XMLSerializer).serializeToString(this.__root);if(/xmlns="http:\/\/www\.w3\.org\/2000\/svg".+xmlns="http:\/\/www\.w3\.org\/2000\/svg/gi.test(s)&&(s=s.replace('xmlns="http://www.w3.org/2000/svg','xmlns:xlink="http://www.w3.org/1999/xlink')),t)for(e=Object.keys(o),r=0;r<e.length;r++)i=e[r],n=o[i],(a=new RegExp(i,"gi")).test(s)&&(s=s.replace(a,n));return s},e.prototype.getSvg=function(){return this.__root},e.prototype.save=function(){var t=this.__createElement("g"),e=this.__closestGroupOrSvg();this.__groupStack.push(e),e.appendChild(t),this.__currentElement=t;const r=this.__getStyleState();this.__debug("save style",r),this.__styleStack.push(r),this.__transformMatrixStack||(this.__transformMatrixStack=[]),this.__transformMatrixStack.push(this.getTransform())},e.prototype.restore=function(){this.__currentElement=this.__groupStack.pop(),this.__currentElementsToStyle=null,this.__currentElement||(this.__currentElement=this.__root.childNodes[1]);var t=this.__styleStack.pop();this.__debug("restore style",t),this.__applyStyleState(t),this.__transformMatrixStack&&this.__transformMatrixStack.length>0&&this.setTransform(this.__transformMatrixStack.pop())},e.prototype.beginPath=function(){var t;this.__currentDefaultPath="",this.__currentPosition={},t=this.__createElement("path",{},!0),this.__closestGroupOrSvg().appendChild(t),this.__currentElement=t},e.prototype.__applyCurrentDefaultPath=function(){var t=this.__currentElement;"path"===t.nodeName?t.setAttribute("d",this.__currentDefaultPath):console.error("Attempted to apply path command to node",t.nodeName)},e.prototype.__addPathCommand=function(t){this.__currentDefaultPath+=" ",this.__currentDefaultPath+=t},e.prototype.moveTo=function(t,e){"path"!==this.__currentElement.nodeName&&this.beginPath(),this.__currentPosition={x:t,y:e},this.__addPathCommand(s("M {x} {y}",{x:this.__matrixTransform(t,e).x,y:this.__matrixTransform(t,e).y}))},e.prototype.closePath=function(){this.__currentDefaultPath&&this.__addPathCommand("Z")},e.prototype.lineTo=function(t,e){this.__currentPosition={x:t,y:e},this.__currentDefaultPath.indexOf("M")>-1?this.__addPathCommand(s("L {x} {y}",{x:this.__matrixTransform(t,e).x,y:this.__matrixTransform(t,e).y})):this.__addPathCommand(s("M {x} {y}",{x:this.__matrixTransform(t,e).x,y:this.__matrixTransform(t,e).y}))},e.prototype.bezierCurveTo=function(t,e,r,i,n,a){this.__currentPosition={x:n,y:a},this.__addPathCommand(s("C {cp1x} {cp1y} {cp2x} {cp2y} {x} {y}",{cp1x:this.__matrixTransform(t,e).x,cp1y:this.__matrixTransform(t,e).y,cp2x:this.__matrixTransform(r,i).x,cp2y:this.__matrixTransform(r,i).y,x:this.__matrixTransform(n,a).x,y:this.__matrixTransform(n,a).y}))},e.prototype.quadraticCurveTo=function(t,e,r,i){this.__currentPosition={x:r,y:i},this.__addPathCommand(s("Q {cpx} {cpy} {x} {y}",{cpx:this.__matrixTransform(t,e).x,cpy:this.__matrixTransform(t,e).y,x:this.__matrixTransform(r,i).x,y:this.__matrixTransform(r,i).y}))};var c=function(t){var e=Math.sqrt(t[0]*t[0]+t[1]*t[1]);return[t[0]/e,t[1]/e]};return e.prototype.arcTo=function(t,e,r,i,n){var a=this.__currentPosition&&this.__currentPosition.x,o=this.__currentPosition&&this.__currentPosition.y;if(void 0!==a&&void 0!==o){if(n<0)throw new Error("IndexSizeError: The radius provided ("+n+") is negative.");if(a===t&&o===e||t===r&&e===i||0===n)this.lineTo(t,e);else{var s=c([a-t,o-e]),l=c([r-t,i-e]);if(s[0]*l[1]!=s[1]*l[0]){var h=s[0]*l[0]+s[1]*l[1],p=Math.acos(Math.abs(h)),u=c([s[0]+l[0],s[1]+l[1]]),f=n/Math.sin(p/2),d=t+f*u[0],_=e+f*u[1],g=[-s[1],s[0]],m=[l[1],-l[0]],v=function(t){var e=t[0];return t[1]>=0?Math.acos(e):-Math.acos(e)},y=v(g),w=v(m);this.lineTo(d+g[0]*n,_+g[1]*n),this.arc(d,_,n,y,w)}else this.lineTo(t,e)}}},e.prototype.stroke=function(){"path"===this.__currentElement.nodeName&&this.__currentElement.setAttribute("paint-order","fill stroke markers"),this.__applyCurrentDefaultPath(),this.__applyStyleToCurrentElement("stroke")},e.prototype.fill=function(){"path"===this.__currentElement.nodeName&&this.__currentElement.setAttribute("paint-order","stroke fill markers"),this.__applyCurrentDefaultPath(),this.__applyStyleToCurrentElement("fill")},e.prototype.rect=function(t,e,r,i){"path"!==this.__currentElement.nodeName&&this.beginPath(),this.moveTo(t,e),this.lineTo(t+r,e),this.lineTo(t+r,e+i),this.lineTo(t,e+i),this.lineTo(t,e),this.closePath()},e.prototype.fillRect=function(t,e,r,i){let{a:n,b:a,c:o,d:s,e:l,f:h}=this.getTransform();var c;JSON.stringify([n,a,o,s,l,h])===JSON.stringify([1,0,0,1,0,0])&&0===t&&0===e&&r===this.width&&i===this.height&&this.__clearCanvas(),c=this.__createElement("rect",{x:t,y:e,width:r,height:i},!0),this.__closestGroupOrSvg().appendChild(c),this.__currentElement=c,this.__applyTransformation(c),this.__applyStyleToCurrentElement("fill")},e.prototype.strokeRect=function(t,e,r,i){var n;n=this.__createElement("rect",{x:t,y:e,width:r,height:i},!0),this.__closestGroupOrSvg().appendChild(n),this.__currentElement=n,this.__applyTransformation(n),this.__applyStyleToCurrentElement("stroke")},e.prototype.__clearCanvas=function(){var t=this.__root.childNodes[1];this.__root.removeChild(t),this.__currentElement=this.__document.createElementNS("http://www.w3.org/2000/svg","g"),this.__root.appendChild(this.__currentElement),this.__groupStack=[]},e.prototype.clearRect=function(t,e,r,i){let{a:n,b:a,c:o,d:s,e:l,f:h}=this.getTransform();if(JSON.stringify([n,a,o,s,l,h])!==JSON.stringify([1,0,0,1,0,0])||0!==t||0!==e||r!==this.width||i!==this.height){var c,p=this.__closestGroupOrSvg();c=this.__createElement("rect",{x:t,y:e,width:r,height:i,fill:"#FFFFFF"},!0),this.__applyTransformation(c),p.appendChild(c)}else this.__clearCanvas()},e.prototype.createLinearGradient=function(t,e,i,n){var a=this.__createElement("linearGradient",{id:l(this.__ids),x1:t+"px",x2:i+"px",y1:e+"px",y2:n+"px",gradientUnits:"userSpaceOnUse"},!1);return this.__defs.appendChild(a),new r(a,this)},e.prototype.createRadialGradient=function(t,e,i,n,a,o){var s=this.__createElement("radialGradient",{id:l(this.__ids),cx:n+"px",cy:a+"px",r:o+"px",fx:t+"px",fy:e+"px",gradientUnits:"userSpaceOnUse"},!1);return this.__defs.appendChild(s),new r(s,this)},e.prototype.__parseFont=function(){var t=/^\s*(?=(?:(?:[-a-z]+\s*){0,2}(italic|oblique))?)(?=(?:(?:[-a-z]+\s*){0,2}(small-caps))?)(?=(?:(?:[-a-z]+\s*){0,2}(bold(?:er)?|lighter|[1-9]00))?)(?:(?:normal|\1|\2|\3)\s*){0,3}((?:xx?-)?(?:small|large)|medium|smaller|larger|[.\d]+(?:\%|in|[cem]m|ex|p[ctx]))(?:\s*\/\s*(normal|[.\d]+(?:\%|in|[cem]m|ex|p[ctx])))?\s*([-,\'\"\sa-z0-9]+?)\s*$/i.exec(this.font),e={style:t[1]||"normal",size:t[4]||"10px",family:t[6]||"sans-serif",weight:t[3]||"normal",decoration:t[2]||"normal",href:null};return"underline"===this.__fontUnderline&&(e.decoration="underline"),this.__fontHref&&(e.href=this.__fontHref),e},e.prototype.__wrapTextLink=function(t,e){if(t.href){var r=this.__createElement("a");return r.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",t.href),r.appendChild(e),r}return e},e.prototype.__applyText=function(t,e,r,i){var n,a,o=this.__parseFont(),s=this.__closestGroupOrSvg(),l=this.__createElement("text",{"font-family":o.family,"font-size":o.size,"font-style":o.style,"font-weight":o.weight,"text-decoration":o.decoration,x:e,y:r,"text-anchor":(n=this.textAlign,a={left:"start",right:"end",center:"middle",start:"start",end:"end"},a[n]||a.start),"dominant-baseline":h(this.textBaseline)},!0);l.appendChild(this.__document.createTextNode(t)),this.__currentElement=l,this.__applyTransformation(l),this.__applyStyleToCurrentElement(i),s.appendChild(this.__wrapTextLink(o,l))},e.prototype.fillText=function(t,e,r){this.__applyText(t,e,r,"fill")},e.prototype.strokeText=function(t,e,r){this.__applyText(t,e,r,"stroke")},e.prototype.measureText=function(t){return this.__ctx.font=this.font,this.__ctx.measureText(t)},e.prototype.arc=function(t,e,r,i,n,a){if(i!==n){(i%=2*Math.PI)===(n%=2*Math.PI)&&(n=(n+2*Math.PI-.001*(a?-1:1))%(2*Math.PI));var o=t+r*Math.cos(n),l=e+r*Math.sin(n),h=t+r*Math.cos(i),c=e+r*Math.sin(i),p=a?0:1,u=0,f=n-i;f<0&&(f+=2*Math.PI),u=a?f>Math.PI?0:1:f>Math.PI?1:0,this.lineTo(h,c),this.__addPathCommand(s("A {rx} {ry} {xAxisRotation} {largeArcFlag} {sweepFlag} {endX} {endY}",{rx:r,ry:r,xAxisRotation:0,largeArcFlag:u,sweepFlag:p,endX:this.__matrixTransform(o,l).x,endY:this.__matrixTransform(o,l).y})),this.__currentPosition={x:o,y:l}}},e.prototype.clip=function(){var t=this.__closestGroupOrSvg(),e=this.__createElement("clipPath"),r=l(this.__ids),i=this.__createElement("g");this.__applyCurrentDefaultPath(),t.removeChild(this.__currentElement),e.setAttribute("id",r),e.appendChild(this.__currentElement),this.__defs.appendChild(e),t.setAttribute("clip-path",s("url(#{id})",{id:r})),t.appendChild(i),this.__currentElement=i},e.prototype.drawImage=function(){var t,r,i,n,a,o,s,l,h,c,p,u,f,d=Array.prototype.slice.call(arguments),_=d[0],g=0,m=0;if(3===d.length)t=d[1],r=d[2],i=a=_.width,n=o=_.height;else if(5===d.length)t=d[1],r=d[2],i=d[3],n=d[4],a=_.width,o=_.height;else{if(9!==d.length)throw new Error("Invalid number of arguments passed to drawImage: "+arguments.length);g=d[1],m=d[2],a=d[3],o=d[4],t=d[5],r=d[6],i=d[7],n=d[8]}s=this.__closestGroupOrSvg();const v=this.getTransform().translate(t,r);if(_ instanceof e){if((l=_.getSvg().cloneNode(!0)).childNodes&&l.childNodes.length>1){for(h=l.childNodes[0];h.childNodes.length;)f=h.childNodes[0].getAttribute("id"),this.__ids[f]=f,this.__defs.appendChild(h.childNodes[0]);(c=l.childNodes[1])&&(this.__applyTransformation(c,v),s.appendChild(c))}}else"CANVAS"!==_.nodeName&&"IMG"!==_.nodeName||((p=this.__createElement("image")).setAttribute("width",i),p.setAttribute("height",n),p.setAttribute("preserveAspectRatio","none"),(g||m||a!==_.width||o!==_.height)&&((u=this.__document.createElement("canvas")).width=i,u.height=n,u.getContext("2d").drawImage(_,g,m,a,o,0,0,i,n),_=u),this.__applyTransformation(p,v),p.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href","CANVAS"===_.nodeName?_.toDataURL():_.getAttribute("src")),s.appendChild(p))},e.prototype.createPattern=function(t,r){var n,a=this.__document.createElementNS("http://www.w3.org/2000/svg","pattern"),o=l(this.__ids);return a.setAttribute("id",o),a.setAttribute("width",t.width),a.setAttribute("height",t.height),a.setAttribute("patternUnits","userSpaceOnUse"),"CANVAS"===t.nodeName||"IMG"===t.nodeName?((n=this.__document.createElementNS("http://www.w3.org/2000/svg","image")).setAttribute("width",t.width),n.setAttribute("height",t.height),n.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href","CANVAS"===t.nodeName?t.toDataURL():t.getAttribute("src")),a.appendChild(n),this.__defs.appendChild(a)):t instanceof e&&(a.appendChild(t.__root.childNodes[1]),this.__defs.appendChild(a)),new i(a,this)},e.prototype.setLineDash=function(t){t&&t.length>0?this.lineDash=t.join(","):this.lineDash=null},e.prototype.setTransform=function(t,e,r,i,n,a){t instanceof DOMMatrix?this.__transformMatrix=new DOMMatrix([t.a,t.b,t.c,t.d,t.e,t.f]):this.__transformMatrix=new DOMMatrix([t,e,r,i,n,a])},e.prototype.getTransform=function(){let{a:t,b:e,c:r,d:i,e:n,f:a}=this.__transformMatrix;return new DOMMatrix([t,e,r,i,n,a])},e.prototype.resetTransform=function(){this.setTransform(1,0,0,1,0,0)},e.prototype.scale=function(t,e){if(void 0===e&&(e=t),isNaN(t)||isNaN(e)||!isFinite(t)||!isFinite(e))return;let r=this.getTransform().scale(t,e);this.setTransform(r)},e.prototype.rotate=function(t){let e=this.getTransform().multiply(new DOMMatrix([Math.cos(t),Math.sin(t),-Math.sin(t),Math.cos(t),0,0]));this.setTransform(e)},e.prototype.translate=function(t,e){const r=this.getTransform().translate(t,e);this.setTransform(r)},e.prototype.transform=function(t,e,r,i,n,a){const o=this.getTransform().multiply(new DOMMatrix([t,e,r,i,n,a]));this.setTransform(o)},e.prototype.__matrixTransform=function(t,e){return new DOMPoint(t,e).matrixTransform(this.__transformMatrix)},e.prototype.getImageData=function(t,e,r,i,n){return a.getImageData(this.getSvg(),this.width,this.height,t,e,r,i,n)},e.prototype.drawFocusRing=function(){},e.prototype.createImageData=function(){},e.prototype.putImageData=function(){},e.prototype.globalCompositeOperation=function(){},e}();function s(t){this.ctx=new o(t),this.svg=this.ctx.__root;var e=this.svg,r=this,i=document.createElement("div");i.style.display="inline-block",i.appendChild(e),this.wrapper=i,Object.defineProperty(this,"className",{get:function(){return i.getAttribute("class")||""},set:function(t){return i.setAttribute("class",t)}}),["width","height"].forEach((function(t){Object.defineProperty(r,t,{get:function(){return 0|e.getAttribute(t)},set:function(n){if(!isNaN(n)&&void 0!==n)return r.ctx[t]=n,e.setAttribute(t,n),i[t]=n}})})),["style","id"].forEach((function(t){Object.defineProperty(r,t,{get:function(){return i[t]},set:function(e){if(void 0!==e)return i[t]=e}})})),["getBoundingClientRect"].forEach((function(t){r[t]=function(){return e[t]()}}))}s.prototype.getContext=function(t){if("2d"!==t)throw new Error("Unsupported type of context for SVGCanvas");return this.ctx},s.prototype.toObjectURL=function(){var t=(new XMLSerializer).serializeToString(this.svg),e=new Blob([t],{type:"image/svg+xml;charset=utf-8"});return URL.createObjectURL(e)},s.prototype.toDataURL=function(t,e,r){return a.toDataURL(this.svg,this.width,this.height,t,e,r)},s.prototype.addEventListener=function(){return this.svg.addEventListener.apply(this.svg,arguments)},s.prototype.getElement=function(){return this.wrapper};var l=s;function h(t){var e=function(e,r,i){var n=[];return[["left",-1,0],["right",1,0],["up",0,-1],["down",0,1]].forEach((function(i){n.push(t.SVGElement.create("feOffset",{in:e,result:r+"-"+i[0],dx:i[1],dy:i[2]}))})),[[null,e],[r+"-left",r+"-tmp-0"],[r+"-right",r+"-tmp-1"],[r+"-up",r+"-tmp-2"],[r+"-down",r+"-tmp-3"]].forEach((function(e,r,a){0!==r&&n.push(t.SVGElement.create("feBlend",{in:a[r-1][1],in2:e[0],result:e[1],mode:i}))})),n};t.SVGFilters={apply:function(e,r,i,n){var a=JSON.parse(e.attribute("data-p5-svg-filters")||"[]");if(r&&a.push([r,i]),e.attribute("data-p5-svg-filters",JSON.stringify(a)),0!==a.length){var o=a.map((function(e,r){var i=0===r?"SourceGraphic":"result-"+(r-1),n="result-"+r,a=t.SVGFilters[e[0]].call(null,i,n,e[1]);return Array.isArray(a)?a:[a]})),s=e.attribute("data-p5-svg-filter-id");s||(s="p5-svg-"+(Date.now().toString()+Math.random().toString().replace(/0\./,"")),e.attribute("data-p5-svg-filter-id",s)),e.attribute("filter","url(#"+s+")");var l=t.SVGElement.create("filter",{id:s});o.forEach((function(t){t.forEach((function(t){l.append(t)}))}));var h=n.querySelectorAll("#"+s)[0];h?h.parentNode.replaceChild(l.elt,h):n.appendChild(l.elt)}else e.attribute("filter",null)},blur:function(e,r,i){return t.SVGElement.create("feGaussianBlur",{stdDeviation:i+"",in:e,result:r,"color-interpolation-filters":"sRGB"})},colorMatrix:function(e,r,i){return t.SVGElement.create("feColorMatrix",{type:"matrix",values:i.join(" "),"color-interpolation-filters":"sRGB",in:e,result:r})},gray:function(e,r){return t.SVGFilters.colorMatrix(e,r,[.2126,.7152,.0722,0,0,.2126,.7152,.0722,0,0,.2126,.7152,.0722,0,0,0,0,0,1,0])},threshold:function(e,r,i){var n=[];n.push(t.SVGFilters.gray(e,r+"-tmp"));var a=t.SVGElement.create("feComponentTransfer",{in:r+"-tmp",result:r}),o=Math.floor(255*i);return["R","G","B"].forEach((function(e){var r=t.SVGElement.create("feFunc"+e,{type:"linear",slope:255,intercept:-1*(o-1)});a.append(r)})),n.push(a),n},invert:function(e,r){return t.SVGFilters.colorMatrix(e,r,[-1,0,0,0,1,0,-1,0,0,1,0,0,-1,0,1,0,0,0,1,0])},opaque:function(e,r){return t.SVGFilters.colorMatrix(e,r,[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,1])},posterize:function(e,r,i){if((i=parseInt(i+"",10))<2||i>255)throw new Error("Level must be greater than 2 and less than 255 for posterize");var n=function(t){for(var e=[],r=0;r<256;r++){var i=t(r);e.push(i/255)}return e}((function(t){return 255*(t*i>>8)/(i-1)})),a=t.SVGElement.create("feComponentTransfer",{in:e,result:r,"color-interpolation-filters":"sRGB"});return["R","G","B"].forEach((function(e){var r=t.SVGElement.create("feFunc"+e,{type:"discrete",tableValues:n.join(" ")});a.append(r)})),a},erode:function(t,r){return e(t,r,"darken")},dilate:function(t,r){return e(t,r,"lighten")}}}var c={SVG:"svg"};function p(t){t.prototype._makeSVGFrame=function(t){var e=t.filename||"untitled",r=t.extension;r=r||this._checkFileExtension(e,r)[1];var i=new RegExp("\\."+r+"$");e=e.replace(i,""),""===r&&(r="svg");var n={png:"image/png",jpeg:"image/jpeg",jpg:"image/jpeg",svg:"image/svg+xml"}[r];if(!n)throw new Error("Fail to getFrame, invalid extension: "+r+", please use png | jpeg | jpg | svg.");!function(t,e,r){var i=(new XMLSerializer).serializeToString(t);if(i="data:image/svg+xml;charset=utf-8,"+encodeURIComponent(i),"image/svg+xml"!=e){var n=new Image,a=document.createElement("canvas"),o=a.getContext("2d");n.onload=function(){a.width=n.width,a.height=n.height,o.drawImage(n,0,0);var t=a.toDataURL(e);r(null,t)},n.src=i}else r(null,i)}(t.svg||this._renderer.svg,n,(function(i,a){a=a.replace(n,"image/octet-stream"),t.callback(i,{imageData:a,filename:e,ext:r})}))},t.prototype.saveSVG=function(){for(var e,r=this,i=[],n=0;n<arguments.length;n++)i[n]=arguments[n];(i=[i[0],i[1],i[2]])[0]instanceof t.Graphics&&(e=i[0]._renderer.svg,i.shift()),i[0]&&i[0].elt&&(e=i[0].elt,i.shift()),"object"==typeof i[0]&&(e=i[0],i.shift());var a=i[0],o=i[1];this._makeSVGFrame({svg:e,filename:a,extension:o,callback:function(t,e){if(t)throw t;r.downloadFile(e.imageData,e.filename,e.ext)}})};var e=t.prototype.saveFrames;t.prototype.saveFrames=function(){for(var r=this,i=[],n=0;n<arguments.length;n++)i[n]=arguments[n];var a=i[0],o=i[1],s=i[2],l=i[3],h=i[4];if(!this._renderer.svg)return e.apply(this,i);s=s||3,s=t.prototype.constrain(s,0,15),s*=1e3,l=l||15,l=t.prototype.constrain(l,0,22);var c=0,p=[],u=0,f=setInterval((function(){!function(t){u++,r._makeSVGFrame({filename:a+t,extension:o,callback:function(e,r){if(e)throw e;p[t]=r,u--}})}(c),c++}),1e3/l),d=function(){u>0?setTimeout((function(){d()}),10):h?h(p):p.forEach((function(t){r.downloadFile(t.imageData,t.filename,t.ext)}))};setTimeout((function(){clearInterval(f),d()}),s+.01)};var r=t.prototype.save;t.prototype.save=function(){for(var e,i=[],n=0;n<arguments.length;n++)i[n]=arguments[n];i[0]instanceof t.Graphics&&(e=i[0].elt.svg,i.shift());i[0]&&i[0].elt&&(e=i[0].elt,i.shift()),"object"==typeof i[0]&&(e=i[0],i.shift()),e=e||this._renderer&&this._renderer.svg;var a=i[0],o=this._checkFileExtension(a,"")[1];if(!(e&&e.nodeName&&"svg"===e.nodeName.toLowerCase()&&["jpeg","png","jpg","svg",""].indexOf(o)>-1))return r.apply(this,i);this.saveSVG(e,a)},t.prototype._svg_get=function(t,e,r){if(0===t.indexOf("data:")){if(-1===t.indexOf(","))return void r(new Error("Fail to parse dataurl: "+t));var i=t.split(",").pop();return setTimeout((function(){i=t.indexOf(";base64,")>-1?atob(i):decodeURIComponent(i),e(i)}),1),i}return this.httpGet(t,e),null},t.prototype.loadSVG=function(e,r,i){var n=this,a=document.createElement("div"),o=new t.SVGElement(a);return this._incrementPreload(),new Promise((function(t,r){n._svg_get(e,(function(e){a.innerHTML=e;var i=a.querySelector("svg");i?(o.elt=i,t(o)):r("Fail to create <svg>.")}),r)})).then((function(t){r&&r(t)})).catch((function(t){i&&i(t)})).finally((function(){n._decrementPreload()})),o},t.prototype.getDataURL=function(){return this._renderer.elt.toDataURL("image/svg+xml")}}var u=function(e){e.prototype.querySVG=function(t){var r=this._renderer&&this._renderer.svg;return r?e.SVGElement.prototype.query.call({elt:r},t):null},e.SVGElement=function(e){function r(){var t=null!==e&&e.apply(this,arguments)||this;return t.attribute=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return 3===t.length?(this.elt.setAttributeNS(t[0],t[1],t[2]),this):2===t.length?(this.elt.setAttribute(t[0],t[1]),this):1===t.length?this.elt.getAttribute(t[0]):this},t}return function(e,r){function i(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(i.prototype=r.prototype,new i)}(r,e),r.prototype.query=function(t){for(var e=this.elt.querySelectorAll(t),i=[],n=0;n<e.length;n++)i[n]=new r(e[n]);return i},r.prototype.append=function(t){var e=t.elt||t;return this.elt.appendChild(e),this},r.create=function(t,e){e=e||{};var i=document.createElementNS("http://www.w3.org/2000/svg",t);return Object.keys(e).forEach((function(t){i.setAttribute(t,e[t])})),new r(i)},r.prototype.parentNode=function(t){if(!t)return new r(this.elt.parentNode);for(var e=this;e;)if((e=this.parentNode())&&e.elt.matches(t))return e;return null},r}(e.Element)};function f(t){var n=t;return function(t){function n(e,r,n){var a=new l({debug:i}),o=a.svg,s=e.parentNode,h=e.id,c=e.className;s.replaceChild(a.getElement(),e),a.id=h,a.className=c,(e=a).parentNode={removeChild:function(t){if(t===e){var r=a.getElement();r.parentNode.removeChild(r)}}};var p=new Proxy(r,{get:function(t,e){return"_pixelDensity"===e?1:t[e]}});return t.Renderer2D.call(this,e,p,n),this.isSVG=!0,this.svg=o,this}n.prototype=Object.create(t.Renderer2D.prototype),n.prototype._applyDefaults=function(){t.Renderer2D.prototype._applyDefaults.call(this),this.drawingContext.lineWidth=1},n.prototype.resize=function(e,r){e&&r&&(this.width===e&&this.height===r||this.drawingContext.__clearCanvas(),t.Renderer2D.prototype.resize.call(this,e,r),this.svg.setAttribute("viewBox",[0,0,e,r].join(" ")))},n.prototype.clear=function(){t.Renderer2D.prototype.clear.call(this),this.drawingContext.__clearCanvas()},n.prototype.appendChild=function(t){t&&t.elt&&(t=t.elt),this.drawingContext.__closestGroupOrSvg().appendChild(t)},n.prototype.image=function(e,r,i,n,a,o,s,l,h){if(!e)throw new Error("Invalid image: "+e);var c=e._renderer&&e._renderer.svg;if(c=(c=c||e.elt&&e.elt.nodeName&&"svg"===e.elt.nodeName.toLowerCase()&&e.elt)||e.nodeName&&"svg"==e.nodeName.toLowerCase()&&e){(c=c.cloneNode(!0)).setAttribute("width",l),c.setAttribute("height",h),c.setAttribute("x",o),c.setAttribute("y",s),(r||i||n||a)&&(n/=this._pInst._pixelDensity,a/=this._pInst._pixelDensity,c.setAttribute("viewBox",[r,i,n,a].join(", ")));var p=t.SVGElement.create("g");this.drawingContext.__applyTransformation(p.elt),p.elt.appendChild(c),this.appendChild(p.elt)}else t.Renderer2D.prototype.image.apply(this,[e,r,i,n,a,o,s,l,h])},n.prototype.parent=function(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];var i={elt:this.elt.getElement()};return t.Element.prototype.parent.apply(i,e)},n.prototype.loadPixels=function(){return e(this,void 0,void 0,(function(){var t,e,i,n,a;return r(this,(function(r){switch(r.label){case 0:return t=this._pixelsState,e=t._pixelDensity,i=this.width*e,n=this.height*e,[4,this.drawingContext.getImageData(0,0,i,n,{async:!0})];case 1:return a=r.sent(),t._setProperty("imageData",a),t._setProperty("pixels",a.data),[2]}}))}))},t.RendererSVG=n}(n),h(n),function(t){var e=t.Graphics;t.Graphics=function(r,i,n,a){var o=n===c.SVG;if(e.apply(this,[r,i,o?a.P2D:n,a]),o){var s=this._renderer.elt;this._renderer=new t.RendererSVG(s,this,!1),s=this._renderer.elt,this.elt=s,this._renderer.resize(r,i),this._renderer._applyDefaults()}return this},t.Graphics.prototype=e.prototype;var r=t.prototype.createCanvas;t.prototype.createCanvas=function(e,i,n){var a=r.apply(this,[e,i,n]);if(n===c.SVG){var o=a.canvas;this._setProperty("_renderer",new t.RendererSVG(o,this,!0)),this._isdefaultGraphics=!0,this._renderer.resize(e,i),this._renderer._applyDefaults()}return this._renderer},t.prototype.createGraphics=function(e,r,i){return new t.Graphics(e,r,i,this)}}(n),p(n),function(t){t.prototype.loadPixels=function(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];return t._validateParameters("loadPixels",e),this._renderer.loadPixels()}}(n),function(t){var e=t.prototype.filter;t.prototype.registerSVGFilter=function(e,r){t.SVGFilters[e]=r},t.prototype.filter=function(r,i){if(this._renderer.svg){for(var n=this._renderer.drawingContext,a=n.__root.querySelectorAll("defs")[0],o=n.__root.childNodes[1],s=t.SVGElement.create("g");o.childNodes.length>0;)s.elt.appendChild(o.childNodes[0]);o.appendChild(s.elt),t.SVGFilters.apply(s,r,i,a),s=t.SVGElement.create("g"),o.appendChild(s.elt),n.__currentElement=s.elt
}else e.apply(this,[r,i])}}(n),u(n),n.prototype.SVG=c.SVG,n}var d=window;void 0!==d.p5&&f(d.p5)}();