@scratch/scratch-svg-renderer 13.5.0 → 13.6.1

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.
@@ -1,2 +1,2 @@
1
- !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.ScratchSVGRenderer=e():t.ScratchSVGRenderer=e()}(global,()=>{return t={619(t,e,r){const s=r(661);t.exports=class{constructor(t,e){this._makeImage=t||(()=>new Image),this._makeCanvas=e||(()=>document.createElement("canvas"))}resize(t,e,r){const s=this._makeCanvas();s.width=e,s.height=t.height;let a=s.getContext("2d");a.imageSmoothingEnabled=!1,a.drawImage(t,0,0,s.width,s.height);const i=this._makeCanvas();return i.width=e,i.height=r,a=i.getContext("2d"),a.imageSmoothingEnabled=!1,a.drawImage(s,0,0,i.width,i.height),i}convertResolution1Bitmap(t,e){const r=this._makeImage();r.src=t,r.onload=()=>{e(null,this.resize(r,2*r.width,2*r.height).toDataURL())},r.onerror=()=>{e("Image load failed")}}getResizedWidthHeight(t,e){const r=480,s=360;if(t<=r&&e<=s)return{width:2*t,height:2*e};if(t<=960&&e<=720)return{width:t,height:e};const a=t/e;return a>=1.3333333333333333?{width:960,height:960/a}:{width:720*a,height:720}}importBitmap(t,e){let r=t;return t instanceof ArrayBuffer&&(r=this.convertBinaryToDataURI(t,e)),new Promise((t,e)=>{const s=this._makeImage();s.src=r,s.onload=()=>{const e=this.getResizedWidthHeight(s.width,s.height);if(e.width===s.width&&e.height===s.height)t(this.convertDataURIToBinary(r));else{const r=this.resize(s,e.width,e.height).toDataURL();t(this.convertDataURIToBinary(r))}},s.onerror=()=>{e("Image load failed")}})}convertDataURIToBinary(t){const e=";base64,",r=t.indexOf(e)+8,s=t.substring(r),a=window.atob(s),i=a.length,n=new Uint8Array(new ArrayBuffer(i));for(let t=0;t<i;t++)n[t]=a.charCodeAt(t);return n}convertBinaryToDataURI(t,e){return"data:".concat(e,";base64,").concat(s.fromByteArray(new Uint8Array(t)))}}},247(t){t.exports=function(t){const e=t.match(/<svg [^>]*>/);e&&-1===e[0].indexOf("xmlns=")&&(t=t.replace("<svg ",'<svg xmlns="http://www.w3.org/2000/svg" ')),e&&-1!==e[0].indexOf("&ns_")&&-1===t.indexOf("<!DOCTYPE")&&(t=t.replace(e[0],e[0].replace(/&ns_[^;]+;/g,"http://ns.adobe.com/Extensibility/1.0/"))),t.includes("data:img/png")&&(t=t.replace(/(<image[^>]+?xlink:href=["'])data:img\/png/g,(t,e)=>"".concat(e,"data:image/png")));const r=/(<[^>]+?xmlns:(?!xml=)[^ ]+=)"http:\/\/www.w3.org\/XML\/1998\/namespace"/g;return null!==t.match(r)&&(t=t.replace(r,(t,e)=>"".concat(e,'"http://dummy.namespace"'))),t=(t=(t=t.replace(/<(\/?)\s*svg:/g,"<$1")).replace(/<metadata>[\s\S]*<\/metadata>/,"<metadata></metadata>")).replace(/<script[\s\S]*>[\s\S]*<\/script>/,"<script><\/script>")}},642(t){t.exports=function(t){const e=[],r=t=>{"text"===t.localName&&e.push(t);for(let e=0;e<t.childNodes.length;e++)r(t.childNodes[e])};r(t);for(const t of e)t.getAttribute("font-family")&&"Helvetica"!==t.getAttribute("font-family")?"Mystery"===t.getAttribute("font-family")?t.setAttribute("font-family","Curly"):"Gloria"===t.getAttribute("font-family")?t.setAttribute("font-family","Handwriting"):"Donegal"===t.getAttribute("font-family")&&t.setAttribute("font-family","Serif"):t.setAttribute("font-family","Sans Serif")}},519(t,e,r){const s=r(770);t.exports=function(t){const e=s();if("string"!=typeof t)throw new Error("SVG to be inlined is not a string");const r=new Set,a=/font-family="([^"]*)"/g;let i=a.exec(t);for(;i;)r.add(i[1]),i=a.exec(t);if(r.size>0){let s="<defs><style>";for(const t of r)Object.prototype.hasOwnProperty.call(e,t)&&(s+="".concat(e[t]));return s+="</style></defs>",t=t.replace(/<svg[^>]*>/,"$&".concat(s))}return t}},276(t,e,r){const s=r(940),a=r(619),i=r(519),n=r(707),o=r(958),c=r(253),l=r(735),u=r(642);t.exports={BitmapAdapter:a,convertFonts:u,inlineSvgFonts:i,loadSvgString:n,sanitizeSvg:o,serializeSvgToString:c,SvgElement:l,SVGRenderer:s}},707(t,e,r){const s=r(735),a=r(642),i=r(386),{sanitizeSvgText:n}=r(958),o=(t,e)=>{const r=[],s=t=>{t.localName!==e&&void 0!==e||!t.getAttribute||r.push(t);for(let e=0;e<t.childNodes.length;e++)s(t.childNodes[e])};return s(t),r},c=t=>{const e=document.createElement("span");let r,s;try{e.innerHTML=t.outerHTML,document.body.appendChild(e),r=e.children[0].getBBox()}finally{document.body.removeChild(e)}s=0===r.width||0===r.height?0:(t=>{let e=0;const r=t=>{t.getAttribute&&(t.getAttribute("stroke")&&(e=Math.max(e,1)),t.getAttribute("stroke-width")&&(e=Math.max(e,Number(t.getAttribute("stroke-width"))||0)));for(let e=0;e<t.childNodes.length;e++)r(t.childNodes[e])};return r(t),e})(t)/2;const a=r.width+2*s,i=r.height+2*s,n=r.x-s,o=r.y-s;t.setAttribute("width",a),t.setAttribute("height",i),t.setAttribute("viewBox","".concat(n," ").concat(o," ").concat(a," ").concat(i))},l=(t,e)=>{e&&(t=>{const e=o(t,"linearGradient");for(const t of e)t.getAttribute("x2")||t.setAttribute("x2","0")})(t),i(t,window),(t=>{const e=o(t,"image"),r="image-rendering: optimizespeed; image-rendering: pixelated;";for(const t of e)t.getAttribute("style")?t.setAttribute("style","".concat(r," ").concat(t.getAttribute("style"))):t.setAttribute("style",r)})(t),e?((t=>{const e=[],r=t=>{"text"===t.localName&&e.push(t);for(let e=0;e<t.childNodes.length;e++)r(t.childNodes[e])};r(t),a(t);for(const r of e){r.removeAttribute("x"),r.removeAttribute("y"),r.setAttribute("alignment-baseline","text-before-edge"),r.setAttribute("xml:space","preserve"),r.getAttribute("font-size")||r.setAttribute("font-size","18");let e=r.textContent;const a=parseFloat(r.getAttribute("font-size")),i=2;let n=0,o=1.2;if("Handwriting"===r.getAttribute("font-family")?(o=2,n=-11*a/22):"Scratch"===r.getAttribute("font-family")?(o=.89,n=-3*a/22):"Curly"===r.getAttribute("font-family")?(o=1.38,n=-6*a/22):"Marker"===r.getAttribute("font-family")?(o=1.45,n=-6*a/22):"Sans Serif"===r.getAttribute("font-family")?(o=1.13,n=-3*a/22):"Serif"===r.getAttribute("font-family")&&(o=1.25,n=-4*a/22),0===r.transform.baseVal.numberOfItems){const e=t.createSVGTransform();r.transform.baseVal.appendItem(e)}const c=r.transform.baseVal.getItem(0).matrix;if(c.e+=c.a*i+c.c*n,c.f+=c.b*i+c.d*n,e&&0===r.childElementCount){r.textContent="";const t=e.split("\n");e="";for(const e of t){const t=s.create("tspan");t.setAttribute("x","0"),t.setAttribute("style","white-space: pre"),t.setAttribute("dy","".concat(o,"em")),t.textContent=e||" ",r.appendChild(t)}}}})(t),c(t),(t=>{const e=o(t);for(const t of e){if(!t.style)continue;const e=t.style.stroke||t.getAttribute("stroke");e&&e.match(/^url\(#.*\)$/)&&(t.style["stroke-linejoin"]="round",t.style["stroke-linecap"]="round")}})(t)):t.getAttribute("viewBox")?t.getAttribute("width")&&t.getAttribute("height")||(t.setAttribute("width",t.viewBox.baseVal.width),t.setAttribute("height",t.viewBox.baseVal.height)):c(t)};t.exports=(t,e)=>{const r=new DOMParser,s=n(t),a=r.parseFromString(s,"text/xml");if(a.childNodes.length<1||"svg"!==a.documentElement.localName)throw new Error("Document does not appear to be SVG.");const i=a.documentElement;return l(i,e),i}},958(t,e,r){const s=r(247),{generate:a,parse:i,walk:n}=r(606),o=r(975),c={},l=t=>t.startsWith("#")||t.startsWith("data:");let u,h;if(o.addHook("beforeSanitizeAttributes",t=>{if(t&&t.href&&t.href.baseVal){const e=t.href.baseVal.replace(/\s/g,"");l(e)||(t.attributes.getNamedItem("xlink:href")&&(t.attributes.removeNamedItem("xlink:href"),delete t["xlink:href"]),t.attributes.getNamedItem("href")&&(t.attributes.removeNamedItem("href"),delete t.href))}if(t&&t.attributes)for(let e=t.attributes.length-1;e>=0;e--){const r=t.attributes[e],s=(r.value||"").toLowerCase().replace(/\s/g,"").match(/url\((.+?)\)/);if(s){const e=s[1].replace(/['"]/g,"");l(e)||t.removeAttribute(r.name)}}return t}),o.addHook("uponSanitizeElement",(t,e)=>{if("style"===e.tagName){const e=i(t.textContent);let r=!1;n(e,(t,e,s)=>{if("Atrule"===t.type&&"import"===t.name.toLowerCase()&&(s.remove(e),r=!0),"Declaration"===t.type&&t.value){let a=!1;n(t.value,t=>{if("Url"===t.type){const e=(t.value.value||"").trim().replace(/['"]/g,"");l(e)||(a=!0)}}),a&&(s.remove(e),r=!0)}}),r&&(t.textContent=a(e))}}),"undefined"==typeof TextDecoder||"undefined"==typeof TextEncoder){const t=r(980);u=t.TextDecoder,h=t.TextEncoder}else u=TextDecoder,h=TextEncoder;c.sanitizeByteStream=function(t){const e=new u,r=new h,s=c.sanitizeSvgText(e.decode(t));return r.encode(s)},c.sanitizeSvgText=function(t){let e=o.sanitize(t,{USE_PROFILES:{svg:!0},FORBID_TAGS:["a","audio","canvas","video"],ADD_DATA_URI_TAGS:["image"]});return e.indexOf("]&gt;")>=0&&(e=e.substring(5,e.length)),e=s(e),e},t.exports=c},253(t,e,r){const s=r(519);t.exports=(t,e)=>{let r=(new XMLSerializer).serializeToString(t);return e&&(r=s(r)),r}},735(t){class e{static get svg(){return"http://www.w3.org/2000/svg"}static get xmlns(){return"http://www.w3.org/2000/xmlns"}static get xlink(){return"http://www.w3.org/1999/xlink"}static attributeNamespace(){return{href:e.xlink,xlink:e.xmlns,xmlns:"".concat(e.xmlns,"/"),"xmlns:xlink":"".concat(e.xmlns,"/")}}static create(t,r,s){return e.set(document.createElementNS(e.svg,t),r,s)}static get(t,r){const s=e.attributeNamespace[r],a=s?t.getAttributeNS(s,r):t.getAttribute(r);return"null"===a?null:a}static set(t,r,s){for(const a in r){let i=r[a];const n=e.attributeNamespace[a];"number"==typeof i&&s&&(i=s.number(i)),n?t.setAttributeNS(n,a,i):t.setAttribute(a,i)}return t}}t.exports=e},940(t,e,r){const s=r(707),a=r(253);t.exports=class{constructor(t){this._canvas=t||document.createElement("canvas"),this._context=this._canvas.getContext("2d"),this._measurements={x:0,y:0,width:0,height:0},this._cachedImage=null,this.loaded=!1}get canvas(){return this._canvas}get size(){return[this._measurements.width,this._measurements.height]}get viewOffset(){return[this._measurements.x,this._measurements.y]}loadString(t,e){this._cachedImage=null;const r=s(t,e);this._svgTag=r,this._measurements={width:r.viewBox.baseVal.width,height:r.viewBox.baseVal.height,x:r.viewBox.baseVal.x,y:r.viewBox.baseVal.y}}loadSVG(t,e,r){this.loadString(t,e),this._createSVGImage(r)}_createSVGImage(t){null===this._cachedImage&&(this._cachedImage=new Image);const e=this._cachedImage;e.onload=()=>{this.loaded=!0,t&&t()};const r=this.toString(!0);e.src="data:image/svg+xml;utf8,".concat(encodeURIComponent(r)),this.loaded=!1}toString(t){return a(this._svgTag,t)}draw(t){if(!this.loaded)throw new Error("SVG image has not finished loading");this._drawFromImage(t)}_drawFromImage(t){if(null===this._cachedImage)return;const e=Number.isFinite(t)?t:1,r=this._measurements;this._canvas.width=r.width*e,this._canvas.height=r.height*e,this._canvas.width<=0||this._canvas.height<=0||this._cachedImage.naturalWidth<=0||this._cachedImage.naturalHeight<=0||(this._context.clearRect(0,0,this._canvas.width,this._canvas.height),this._context.setTransform(e,0,0,e,0,0),this._context.drawImage(this._cachedImage,0,0))}}},386(t,e,r){const s=r(853),a=r(735),i=r(88),n=function(t){let e=s.identity();const r=t.attributes&&t.attributes.transform&&t.attributes.transform.value;if(!r)return e;const a=r.split(/\)\s*/g);for(const t of a){if(!t)break;const r=t.split(/\(\s*/),a=r[0].trim(),n=r[1].split(/[\s,]+/g);for(let t=0;t<n.length;t++)n[t]=parseFloat(n[t]);switch(a){case"matrix":e=s.compose(e,{a:n[0],b:n[1],c:n[2],d:n[3],e:n[4],f:n[5]});break;case"rotate":e=s.compose(e,s.rotateDEG(n[0],n[1]||0,n[2]||0));break;case"translate":e=s.compose(e,s.translate(n[0],n[1]||0));break;case"scale":e=s.compose(e,s.scale(n[0],n[1]||n[0]));break;case"skewX":e=s.compose(e,s.skewDEG(n[0],0));break;case"skewY":e=s.compose(e,s.skewDEG(0,n[0]));break;default:i.error("Couldn't parse: ".concat(a))}}return e},o=function(t){const e=t.a,r=t.b,s=t.c,a=t.d,i=e*a-r*s;if(0!==e||0!==r){const t=Math.sqrt(e*e+r*r);return{x:t,y:i/t}}if(0!==s||0!==a){const t=Math.sqrt(s*s+a*a);return{x:i/t,y:t}}return{x:0,y:0}},c=function(t,e,r,s){r=-r*Math.PI/180;const a=s.a,i=-s.c,n=-s.b,o=s.d,c=a*o-i*n;if(0===c)return null;const l=Math.sin(r),u=Math.cos(r),h=Math.sin(2*r),d=u*u/t/t+l*l/e/e,m=h/t/t-h/e/e,g=l*l/t/t+u*u/e/e,f=d*o*o-m*o*n+g*n*n,b=-2*d*i*o+m*a*o+m*i*n-2*g*a*n,x=d*i*i-m*a*i+g*a*a,p=Math.sqrt(2)*Math.sqrt((f+x-Math.sqrt(f*f+b*b-2*f*x+x*x))/(-b*b+4*f*x)),y=1/Math.sqrt(f+x-1/p/p);let w=(f-1/p/p)/(1/y/y-1/p/p);w<0&&Math.abs(w)<1e-8&&(w=0),w=Math.sqrt(w),Math.abs(1-w)<1e-8&&(w=1);let v=Math.asin(w);w=b/(1/p/p-1/y/y);const A=-v;return Math.abs(Math.sin(2*A)-w)<Math.abs(Math.sin(2*v)-w)&&(v=A),{radiusX:p*c,radiusY:y*c,rotation:180*-v/Math.PI}},l=["circle","ellipse","image","line","path","polygon","polyline","rect","text","use"],u=["a","defs","g","marker","glyph","missing-glyph","pattern","svg","switch","symbol"],h=function(t,e){return Math.sqrt((t*t+e*e)/2)},d=function(t,e,r,i){const n=function(t,e,s,i,n,o){let c,l=a.get(t,e);return null===l?o?(c=o,/%\s*$/.test(c)&&(l=o,c=parseFloat(l))):c=i?null:s?"":0:c=s?l:parseFloat(l),/%\s*$/.test(l)?c/100*(n?1:r[/x|^width/.test(e)?"width":"height"]):c},c=function(t,e,r,s,a,i,o){return e=n(t,e||"x",!1,s,a,i),r=n(t,r||"y",!1,s,a,o),!s||null!==e&&null!==r?{x:e,y:r}:null};let l=e.getElementsByTagName("defs");0===l.length?(l=a.create("defs"),e.appendChild(l)):l=l[0];const u=e.getElementById(t);if(!u)return;const d="radialgradient"===u.tagName.toLowerCase(),m=e.getElementById(t).cloneNode(!0);let g=s.toString(i);g=g.substring(8,g.length-1);const f="".concat(t,"-").concat(g);if(m.setAttribute("id",f),e.getElementById(f))return"url(#".concat(f,")");const b="userSpaceOnUse"!==n(m,"gradientUnits",!0);let x,p,y,w;if(d)x=c(m,"cx","cy",!1,b,"50%","50%"),y=n(m,"r",!1,!1,b,"50%"),w=c(m,"fx","fy",!0,b);else if(x=c(m,"x1","y1",!1,b),p=c(m,"x2","y2",!1,b,"1"),x.x===p.x&&x.y===p.y){const t=m.getElementsByTagName("stop");return t.length&&t[t.length-1].attributes&&t[t.length-1].attributes["stop-color"]?t[t.length-1].attributes["stop-color"].value:null}if(b){const t=s.compose(s.translate(r.x,r.y),s.scale(r.width,r.height));x=s.applyToPoint(t,x),p&&(p=s.applyToPoint(t,p)),y&&(y=h(r.width,r.height)*y),w&&(w=s.applyToPoint(t,w))}if(d){x=s.applyToPoint(i,x);const t=o(i);y=h(t.x,t.y)*y,w&&(w=s.applyToPoint(i,w))}else{const t=(t,e)=>t.x*e.x+t.y*e.y,e=(t,e)=>({x:t*e.x,y:t*e.y}),r=(t,e)=>({x:t.x+e.x,y:t.y+e.y}),a=(t,e)=>({x:t.x-e.x,y:t.y-e.y});let n=Math.abs(x.x-p.x)<1e-8?r(x,{x:1,y:(x.x-p.x)/(p.y-x.y)}):r(x,{x:(p.y-x.y)/(x.x-p.x),y:1});n=s.applyToPoint(i,n),x=s.applyToPoint(i,x),p=s.applyToPoint(i,p);const o=a(n,x),c=a(p,x),l=Math.abs(o.x)<1e-8?{x:1,y:-o.x/o.y}:{x:-o.y/o.x,y:1},u=e(t(c,l)/t(l,l),l);p={x:x.x+u.x,y:x.y+u.y}}return d?(m.setAttribute("cx",Number(x.x.toFixed(4))),m.setAttribute("cy",Number(x.y.toFixed(4))),m.setAttribute("r",Number(y.toFixed(4))),w&&(m.setAttribute("fx",Number(w.x.toFixed(4))),m.setAttribute("fy",Number(w.y.toFixed(4))))):(m.setAttribute("x1",Number(x.x.toFixed(4))),m.setAttribute("y1",Number(x.y.toFixed(4))),m.setAttribute("x2",Number(p.x.toFixed(4))),m.setAttribute("y2",Number(p.y.toFixed(4)))),m.setAttribute("gradientUnits","userSpaceOnUse"),l.appendChild(m),"url(#".concat(f,")")},m=(t,e)=>{const r=t&&t.match(/\((?:["'#]*)([^"')]+)/),s=r&&r[1];return s&&e?s.replace("".concat(e.location.href.split("#")[0],"#"),""):s};t.exports=function(t,e,r){const i=s.identity(),g=(i,f,b,x,p)=>{if(function(t){return t.tagName&&u.includes(t.tagName.toLowerCase())}(i)){i.attributes["stroke-width"]&&(b=i.attributes["stroke-width"].value),i.attributes&&(i.attributes.fill&&(x=i.attributes.fill.value),i.attributes.stroke&&(p=i.attributes.stroke.value));for(let t=0;t<i.childNodes.length;t++)g(i.childNodes[t],s.compose(f,n(i)),b,x,p);i.removeAttribute("transform"),i.removeAttribute("stroke-width"),i.removeAttribute("fill"),i.removeAttribute("stroke")}else if(function(t,e){return!!t.attributes&&(e=t.attributes["stroke-width"]?Number(t.attributes["stroke-width"].value):Number(e))&&t.tagName&&"path"===t.tagName.toLowerCase()&&t.attributes.d&&t.attributes.d.value}(i,b)){if(i.attributes["stroke-width"]&&(b=i.attributes["stroke-width"].value),i.attributes.fill&&(x=i.attributes.fill.value),i.attributes.stroke&&(p=i.attributes.stroke.value),f=s.compose(f,n(i)),s.toString(f)===s.toString(s.identity()))return i.removeAttribute("transform"),i.setAttribute("stroke-width",b),x&&i.setAttribute("fill",x),void(p&&i.setAttribute("stroke",p));const l=m(x,e),u=m(p,e);if(l||u){const s=e.document,n=s.createElement("span");let o;if(r)o=r;else try{s.body.appendChild(n);const t=a.set(s.createElementNS(a.svg,"svg")),e=a.set(s.createElementNS(a.svg,"path"));e.setAttribute("d",i.attributes.d.value),t.appendChild(e),n.appendChild(t),o=t.getBBox()}finally{s.body.removeChild(n)}if(l){const e=d(l,t,o,f);e&&(x=e)}if(u){const e=d(u,t,o,f);e&&(p=e)}}i.setAttribute("d",function(t,e){if(!e||s.toString(e)===s.toString(s.identity()))return t;const r=t&&t.match(/[mlhvcsqtaz][^mlhvcsqtaz]*/gi);let a,i,n,l=!1,u={x:0,y:0},h={x:0,y:0},d="";const m=function(t,e){let r=+a[t];return l&&(r+=u[e]),r},g=function(t){return{x:m(t,"x"),y:m(t+1,"y")}},f=function(t){return Number(t.toFixed(4))},b=function(t){const r=s.applyToPoint(e,t);return"".concat(f(r.x)," ").concat(f(r.y)," ")};for(let t=0,s=r&&r.length;t<s;t++){const s=r[t],x=s[0],p=x.toLowerCase();a=s.match(/[+-]?(?:\d*\.\d+|\d+\.?)(?:[eE][+-]?\d+)?/g);const y=a&&a.length;switch(l=x===p,"z"!==i||/[mz]/.test(p)||(d+="M ".concat(u.x," ").concat(u.y," ")),p){case"m":case"l":{let t="m"===p;for(let e=0;e<y;e+=2)d+=t?"M ":"L ",u=g(e),d+=b(u),t&&(h=u,t=!1);n=u;break}case"h":case"v":{const t="h"===p?"x":"y";u={x:u.x,y:u.y};for(let e=0;e<y;e++)u[t]=m(e,t),d+="L ".concat(b(u));n=u;break}case"c":for(let t=0;t<y;t+=6){const e=g(t);n=g(t+2),u=g(t+4),d+="C ".concat(b(e)).concat(b(n)).concat(b(u))}break;case"s":for(let t=0;t<y;t+=4){const e=/[cs]/.test(i)?{x:2*u.x-n.x,y:2*u.y-n.y}:u;n=g(t),u=g(t+2),d+="C ".concat(b(e)).concat(b(n)).concat(b(u)),i=p}break;case"q":for(let t=0;t<y;t+=4)n=g(t),u=g(t+2),d+="Q ".concat(b(n)).concat(b(u));break;case"t":for(let t=0;t<y;t+=2)n=/[qt]/.test(i)?{x:2*u.x-n.x,y:2*u.y-n.y}:u,u=g(t),d+="Q ".concat(b(n)).concat(b(u)),i=p;break;case"a":for(let t=0;t<y;t+=7){u=g(t+5);const r=+a[t],s=+a[t+1],i=+a[t+2],n=+a[t+3];let l=+a[t+4];const h=c(r,s,i,e),m=o(e);h?((m.x>0&&m.y<0||m.x<0&&m.y>0)&&(l^=1),d+="A ".concat(f(Math.abs(h.radiusX))," ")+"".concat(f(Math.abs(h.radiusY))," ")+"".concat(f(h.rotation)," ").concat(n," ")+"".concat(l," ").concat(b(u))):d+="L ".concat(b(u))}break;case"z":d+="Z ",u=h}i=p}return d}(i.attributes.d.value,f)),i.removeAttribute("transform");const g=o(f);i.setAttribute("stroke-width",h(g.x,g.y)*b),x&&i.setAttribute("fill",x),p&&i.setAttribute("stroke",p)}else(function(t){return t.tagName&&l.includes(t.tagName.toLowerCase())})(i)&&(b&&!i.attributes["stroke-width"]&&i.setAttribute("stroke-width",b),x&&!i.attributes.fill&&i.setAttribute("fill",x),p&&!i.attributes.stroke&&i.setAttribute("stroke",p),f=s.compose(f,n(i)),s.toString(f)===s.toString(s.identity())?i.removeAttribute("transform"):i.setAttribute("transform",s.toString(f)))};g(t,i,1)}},88(t,e,r){const{Logger:s}=r(441);t.exports=new s({name:"scratch-svg-renderer"})},661(t){"use strict";t.exports=require("base64-js")},606(t){"use strict";t.exports=require("css-tree")},980(t){"use strict";t.exports=require("fastestsmallesttextencoderdecoder")},975(t){"use strict";t.exports=require("isomorphic-dompurify")},770(t){"use strict";t.exports=require("scratch-render-fonts")},853(t){"use strict";t.exports=require("transformation-matrix")},441(t){"use strict";t.exports=require("tslog")}},e={},function r(s){var a=e[s];if(void 0!==a)return a.exports;var i=e[s]={exports:{}};return t[s](i,i.exports,r),i.exports}(276);var t,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.ScratchSVGRenderer=e():t.ScratchSVGRenderer=e()}(global,()=>{return t={619(t,e,r){const s=r(661);t.exports=class{constructor(t,e){this._makeImage=t||(()=>new Image),this._makeCanvas=e||(()=>document.createElement("canvas"))}resize(t,e,r){const s=this._makeCanvas();s.width=e,s.height=t.height;let n=s.getContext("2d");n.imageSmoothingEnabled=!1,n.drawImage(t,0,0,s.width,s.height);const i=this._makeCanvas();return i.width=e,i.height=r,n=i.getContext("2d"),n.imageSmoothingEnabled=!1,n.drawImage(s,0,0,i.width,i.height),i}convertResolution1Bitmap(t,e){const r=this._makeImage();r.src=t,r.onload=()=>{e(null,this.resize(r,2*r.width,2*r.height).toDataURL())},r.onerror=()=>{e("Image load failed")}}getResizedWidthHeight(t,e){const r=480,s=360;if(t<=r&&e<=s)return{width:2*t,height:2*e};if(t<=960&&e<=720)return{width:t,height:e};const n=t/e;return n>=1.3333333333333333?{width:960,height:960/n}:{width:720*n,height:720}}importBitmap(t,e){let r=t;return t instanceof ArrayBuffer&&(r=this.convertBinaryToDataURI(t,e)),new Promise((t,e)=>{const s=this._makeImage();s.src=r,s.onload=()=>{const e=this.getResizedWidthHeight(s.width,s.height);if(e.width===s.width&&e.height===s.height)t(this.convertDataURIToBinary(r));else{const r=this.resize(s,e.width,e.height).toDataURL();t(this.convertDataURIToBinary(r))}},s.onerror=()=>{e("Image load failed")}})}convertDataURIToBinary(t){const e=";base64,",r=t.indexOf(e)+8,s=t.substring(r),n=window.atob(s),i=n.length,a=new Uint8Array(new ArrayBuffer(i));for(let t=0;t<i;t++)a[t]=n.charCodeAt(t);return a}convertBinaryToDataURI(t,e){return"data:".concat(e,";base64,").concat(s.fromByteArray(new Uint8Array(t)))}}},247(t){t.exports=function(t){const e=t.match(/<svg [^>]*>/);e&&-1===e[0].indexOf("xmlns=")&&(t=t.replace("<svg ",'<svg xmlns="http://www.w3.org/2000/svg" ')),e&&-1!==e[0].indexOf("&ns_")&&-1===t.indexOf("<!DOCTYPE")&&(t=t.replace(e[0],e[0].replace(/&ns_[^;]+;/g,"http://ns.adobe.com/Extensibility/1.0/"))),t.includes("data:img/png")&&(t=t.replace(/(<image[^>]+?xlink:href=["'])data:img\/png/g,(t,e)=>"".concat(e,"data:image/png")));const r=/(<[^>]+?xmlns:(?!xml=)[^ ]+=)"http:\/\/www.w3.org\/XML\/1998\/namespace"/g;return null!==t.match(r)&&(t=t.replace(r,(t,e)=>"".concat(e,'"http://dummy.namespace"'))),t=(t=(t=t.replace(/<(\/?)\s*svg:/g,"<$1")).replace(/<metadata>[\s\S]*<\/metadata>/,"<metadata></metadata>")).replace(/<script[\s\S]*>[\s\S]*<\/script>/,"<script><\/script>")}},642(t){t.exports=function(t){const e=[],r=t=>{"text"===t.localName&&e.push(t);for(let e=0;e<t.childNodes.length;e++)r(t.childNodes[e])};r(t);for(const t of e)t.getAttribute("font-family")&&"Helvetica"!==t.getAttribute("font-family")?"Mystery"===t.getAttribute("font-family")?t.setAttribute("font-family","Curly"):"Gloria"===t.getAttribute("font-family")?t.setAttribute("font-family","Handwriting"):"Donegal"===t.getAttribute("font-family")&&t.setAttribute("font-family","Serif"):t.setAttribute("font-family","Sans Serif")}},519(t,e,r){const s=r(770);t.exports=function(t){const e=s();if("string"!=typeof t)throw new Error("SVG to be inlined is not a string");const r=new Set,n=/font-family="([^"]*)"/g;let i=n.exec(t);for(;i;)r.add(i[1]),i=n.exec(t);if(r.size>0){let s="<defs><style>";for(const t of r)Object.prototype.hasOwnProperty.call(e,t)&&(s+="".concat(e[t]));return s+="</style></defs>",t=t.replace(/<svg[^>]*>/,"$&".concat(s))}return t}},276(t,e,r){const s=r(940),n=r(619),i=r(519),a=r(707),o=r(958),c=r(253),l=r(735),u=r(642);t.exports={BitmapAdapter:n,convertFonts:u,inlineSvgFonts:i,loadSvgString:a,sanitizeSvg:o,serializeSvgToString:c,SvgElement:l,SVGRenderer:s}},707(t,e,r){const s=r(735),n=r(642),i=r(386),{sanitizeSvgText:a}=r(958),o=(t,e)=>{const r=[],s=t=>{t.localName!==e&&void 0!==e||!t.getAttribute||r.push(t);for(let e=0;e<t.childNodes.length;e++)s(t.childNodes[e])};return s(t),r},c=t=>{const e=document.createElement("span");let r,s;try{e.innerHTML=t.outerHTML,document.body.appendChild(e),r=e.children[0].getBBox()}finally{document.body.removeChild(e)}s=0===r.width||0===r.height?0:(t=>{let e=0;const r=t=>{t.getAttribute&&(t.getAttribute("stroke")&&(e=Math.max(e,1)),t.getAttribute("stroke-width")&&(e=Math.max(e,Number(t.getAttribute("stroke-width"))||0)));for(let e=0;e<t.childNodes.length;e++)r(t.childNodes[e])};return r(t),e})(t)/2;const n=r.width+2*s,i=r.height+2*s,a=r.x-s,o=r.y-s;t.setAttribute("width",n),t.setAttribute("height",i),t.setAttribute("viewBox","".concat(a," ").concat(o," ").concat(n," ").concat(i))},l=(t,e)=>{e&&(t=>{const e=o(t,"linearGradient");for(const t of e)t.getAttribute("x2")||t.setAttribute("x2","0")})(t),i(t,window),(t=>{const e=o(t,"image"),r="image-rendering: optimizespeed; image-rendering: pixelated;";for(const t of e)t.getAttribute("style")?t.setAttribute("style","".concat(r," ").concat(t.getAttribute("style"))):t.setAttribute("style",r)})(t),e?((t=>{const e=[],r=t=>{"text"===t.localName&&e.push(t);for(let e=0;e<t.childNodes.length;e++)r(t.childNodes[e])};r(t),n(t);for(const r of e){r.removeAttribute("x"),r.removeAttribute("y"),r.setAttribute("alignment-baseline","text-before-edge"),r.setAttribute("xml:space","preserve"),r.getAttribute("font-size")||r.setAttribute("font-size","18");let e=r.textContent;const n=parseFloat(r.getAttribute("font-size")),i=2;let a=0,o=1.2;if("Handwriting"===r.getAttribute("font-family")?(o=2,a=-11*n/22):"Scratch"===r.getAttribute("font-family")?(o=.89,a=-3*n/22):"Curly"===r.getAttribute("font-family")?(o=1.38,a=-6*n/22):"Marker"===r.getAttribute("font-family")?(o=1.45,a=-6*n/22):"Sans Serif"===r.getAttribute("font-family")?(o=1.13,a=-3*n/22):"Serif"===r.getAttribute("font-family")&&(o=1.25,a=-4*n/22),0===r.transform.baseVal.numberOfItems){const e=t.createSVGTransform();r.transform.baseVal.appendItem(e)}const c=r.transform.baseVal.getItem(0).matrix;if(c.e+=c.a*i+c.c*a,c.f+=c.b*i+c.d*a,e&&0===r.childElementCount){r.textContent="";const t=e.split("\n");e="";for(const e of t){const t=s.create("tspan");t.setAttribute("x","0"),t.setAttribute("style","white-space: pre"),t.setAttribute("dy","".concat(o,"em")),t.textContent=e||" ",r.appendChild(t)}}}})(t),c(t),(t=>{const e=o(t);for(const t of e){if(!t.style)continue;const e=t.style.stroke||t.getAttribute("stroke");e&&e.match(/^url\(#.*\)$/)&&(t.style["stroke-linejoin"]="round",t.style["stroke-linecap"]="round")}})(t)):t.getAttribute("viewBox")?t.getAttribute("width")&&t.getAttribute("height")||(t.setAttribute("width",t.viewBox.baseVal.width),t.setAttribute("height",t.viewBox.baseVal.height)):c(t)};t.exports=(t,e)=>{const r=new DOMParser,s=a(t),n=r.parseFromString(s,"text/xml");if(n.childNodes.length<1||"svg"!==n.documentElement.localName)throw new Error("Document does not appear to be SVG.");const i=n.documentElement;return l(i,e),i}},958(t,e,r){const s=r(247),{generate:n,parse:i,walk:a}=r(606),{ident:o}=r(368),c=r(975),l={},u=t=>t.startsWith("#")||t.toLowerCase().startsWith("data:"),h=t=>{const e=t.toLowerCase().replace(/\s/g,""),r=/url\((.+?)\)/g;let s;for(;null!==(s=r.exec(e));){const t=s[1].replace(/['"]/g,"");if(!u(t))return!0}return!1},d=t=>{let e=!1;return a(t,t=>{if("Url"===t.type){const r=t.value.trim().replace(/['"]/g,"");u(r)||(e=!0)}"Raw"===t.type&&h(t.value)&&(e=!0)}),e},m=(t,e)=>{const r=o.decode(t);try{return d(i(r,{context:e}))}catch(t){return h(r)}},g=new Set(["href","xlink:href"]);let f,b;if(c.addHook("beforeSanitizeAttributes",t=>{if(!t||!t.attributes)return t;for(let e=t.attributes.length-1;e>=0;e--){const r=t.attributes[e];if(r.value)if(g.has(r.name))u(r.value.replace(/\s/g,""))||t.removeAttribute(r.name);else{const e="style"===r.name?"declarationList":"value";m(r.value,e)&&t.removeAttribute(r.name)}}return t}),c.addHook("uponSanitizeElement",(t,e)=>{if("style"===e.tagName)try{const e=o.decode(t.textContent),r=i(e);let s=e!==t.textContent;a(r,(t,e,r)=>{"Atrule"===t.type&&"import"===t.name.toLowerCase()&&(r.remove(e),s=!0),"Declaration"===t.type&&t.value&&d(t.value)&&(r.remove(e),s=!0)}),s&&(t.textContent=n(r))}catch(e){t.textContent=""}}),"undefined"==typeof TextDecoder||"undefined"==typeof TextEncoder){const t=r(980);f=t.TextDecoder,b=t.TextEncoder}else f=TextDecoder,b=TextEncoder;l.sanitizeByteStream=function(t){const e=new f,r=new b,s=l.sanitizeSvgText(e.decode(t));return r.encode(s)},l.sanitizeSvgText=function(t){let e=c.sanitize(t,{USE_PROFILES:{svg:!0},FORBID_TAGS:["a","audio","canvas","video"],ADD_DATA_URI_TAGS:["image"]});return e.indexOf("]&gt;")>=0&&(e=e.substring(5,e.length)),e=s(e),e},t.exports=l},253(t,e,r){const s=r(519);t.exports=(t,e)=>{let r=(new XMLSerializer).serializeToString(t);return e&&(r=s(r)),r}},735(t){class e{static get svg(){return"http://www.w3.org/2000/svg"}static get xmlns(){return"http://www.w3.org/2000/xmlns"}static get xlink(){return"http://www.w3.org/1999/xlink"}static attributeNamespace(){return{href:e.xlink,xlink:e.xmlns,xmlns:"".concat(e.xmlns,"/"),"xmlns:xlink":"".concat(e.xmlns,"/")}}static create(t,r,s){return e.set(document.createElementNS(e.svg,t),r,s)}static get(t,r){const s=e.attributeNamespace[r],n=s?t.getAttributeNS(s,r):t.getAttribute(r);return"null"===n?null:n}static set(t,r,s){for(const n in r){let i=r[n];const a=e.attributeNamespace[n];"number"==typeof i&&s&&(i=s.number(i)),a?t.setAttributeNS(a,n,i):t.setAttribute(n,i)}return t}}t.exports=e},940(t,e,r){const s=r(707),n=r(253);t.exports=class{constructor(t){this._canvas=t||document.createElement("canvas"),this._context=this._canvas.getContext("2d"),this._measurements={x:0,y:0,width:0,height:0},this._cachedImage=null,this.loaded=!1}get canvas(){return this._canvas}get size(){return[this._measurements.width,this._measurements.height]}get viewOffset(){return[this._measurements.x,this._measurements.y]}loadString(t,e){this._cachedImage=null;const r=s(t,e);this._svgTag=r,this._measurements={width:r.viewBox.baseVal.width,height:r.viewBox.baseVal.height,x:r.viewBox.baseVal.x,y:r.viewBox.baseVal.y}}loadSVG(t,e,r){this.loadString(t,e),this._createSVGImage(r)}_createSVGImage(t){null===this._cachedImage&&(this._cachedImage=new Image);const e=this._cachedImage;e.onload=()=>{this.loaded=!0,t&&t()};const r=this.toString(!0);e.src="data:image/svg+xml;utf8,".concat(encodeURIComponent(r)),this.loaded=!1}toString(t){return n(this._svgTag,t)}draw(t){if(!this.loaded)throw new Error("SVG image has not finished loading");this._drawFromImage(t)}_drawFromImage(t){if(null===this._cachedImage)return;const e=Number.isFinite(t)?t:1,r=this._measurements;this._canvas.width=r.width*e,this._canvas.height=r.height*e,this._canvas.width<=0||this._canvas.height<=0||this._cachedImage.naturalWidth<=0||this._cachedImage.naturalHeight<=0||(this._context.clearRect(0,0,this._canvas.width,this._canvas.height),this._context.setTransform(e,0,0,e,0,0),this._context.drawImage(this._cachedImage,0,0))}}},386(t,e,r){const s=r(853),n=r(735),i=r(88),a=function(t){let e=s.identity();const r=t.attributes&&t.attributes.transform&&t.attributes.transform.value;if(!r)return e;const n=r.split(/\)\s*/g);for(const t of n){if(!t)break;const r=t.split(/\(\s*/),n=r[0].trim(),a=r[1].split(/[\s,]+/g);for(let t=0;t<a.length;t++)a[t]=parseFloat(a[t]);switch(n){case"matrix":e=s.compose(e,{a:a[0],b:a[1],c:a[2],d:a[3],e:a[4],f:a[5]});break;case"rotate":e=s.compose(e,s.rotateDEG(a[0],a[1]||0,a[2]||0));break;case"translate":e=s.compose(e,s.translate(a[0],a[1]||0));break;case"scale":e=s.compose(e,s.scale(a[0],a[1]||a[0]));break;case"skewX":e=s.compose(e,s.skewDEG(a[0],0));break;case"skewY":e=s.compose(e,s.skewDEG(0,a[0]));break;default:i.error("Couldn't parse: ".concat(n))}}return e},o=function(t){const e=t.a,r=t.b,s=t.c,n=t.d,i=e*n-r*s;if(0!==e||0!==r){const t=Math.sqrt(e*e+r*r);return{x:t,y:i/t}}if(0!==s||0!==n){const t=Math.sqrt(s*s+n*n);return{x:i/t,y:t}}return{x:0,y:0}},c=function(t,e,r,s){r=-r*Math.PI/180;const n=s.a,i=-s.c,a=-s.b,o=s.d,c=n*o-i*a;if(0===c)return null;const l=Math.sin(r),u=Math.cos(r),h=Math.sin(2*r),d=u*u/t/t+l*l/e/e,m=h/t/t-h/e/e,g=l*l/t/t+u*u/e/e,f=d*o*o-m*o*a+g*a*a,b=-2*d*i*o+m*n*o+m*i*a-2*g*n*a,x=d*i*i-m*n*i+g*n*n,p=Math.sqrt(2)*Math.sqrt((f+x-Math.sqrt(f*f+b*b-2*f*x+x*x))/(-b*b+4*f*x)),y=1/Math.sqrt(f+x-1/p/p);let w=(f-1/p/p)/(1/y/y-1/p/p);w<0&&Math.abs(w)<1e-8&&(w=0),w=Math.sqrt(w),Math.abs(1-w)<1e-8&&(w=1);let v=Math.asin(w);w=b/(1/p/p-1/y/y);const A=-v;return Math.abs(Math.sin(2*A)-w)<Math.abs(Math.sin(2*v)-w)&&(v=A),{radiusX:p*c,radiusY:y*c,rotation:180*-v/Math.PI}},l=["circle","ellipse","image","line","path","polygon","polyline","rect","text","use"],u=["a","defs","g","marker","glyph","missing-glyph","pattern","svg","switch","symbol"],h=function(t,e){return Math.sqrt((t*t+e*e)/2)},d=function(t,e,r,i){const a=function(t,e,s,i,a,o){let c,l=n.get(t,e);return null===l?o?(c=o,/%\s*$/.test(c)&&(l=o,c=parseFloat(l))):c=i?null:s?"":0:c=s?l:parseFloat(l),/%\s*$/.test(l)?c/100*(a?1:r[/x|^width/.test(e)?"width":"height"]):c},c=function(t,e,r,s,n,i,o){return e=a(t,e||"x",!1,s,n,i),r=a(t,r||"y",!1,s,n,o),!s||null!==e&&null!==r?{x:e,y:r}:null};let l=e.getElementsByTagName("defs");0===l.length?(l=n.create("defs"),e.appendChild(l)):l=l[0];const u=e.getElementById(t);if(!u)return;const d="radialgradient"===u.tagName.toLowerCase(),m=e.getElementById(t).cloneNode(!0);let g=s.toString(i);g=g.substring(8,g.length-1);const f="".concat(t,"-").concat(g);if(m.setAttribute("id",f),e.getElementById(f))return"url(#".concat(f,")");const b="userSpaceOnUse"!==a(m,"gradientUnits",!0);let x,p,y,w;if(d)x=c(m,"cx","cy",!1,b,"50%","50%"),y=a(m,"r",!1,!1,b,"50%"),w=c(m,"fx","fy",!0,b);else if(x=c(m,"x1","y1",!1,b),p=c(m,"x2","y2",!1,b,"1"),x.x===p.x&&x.y===p.y){const t=m.getElementsByTagName("stop");return t.length&&t[t.length-1].attributes&&t[t.length-1].attributes["stop-color"]?t[t.length-1].attributes["stop-color"].value:null}if(b){const t=s.compose(s.translate(r.x,r.y),s.scale(r.width,r.height));x=s.applyToPoint(t,x),p&&(p=s.applyToPoint(t,p)),y&&(y=h(r.width,r.height)*y),w&&(w=s.applyToPoint(t,w))}if(d){x=s.applyToPoint(i,x);const t=o(i);y=h(t.x,t.y)*y,w&&(w=s.applyToPoint(i,w))}else{const t=(t,e)=>t.x*e.x+t.y*e.y,e=(t,e)=>({x:t*e.x,y:t*e.y}),r=(t,e)=>({x:t.x+e.x,y:t.y+e.y}),n=(t,e)=>({x:t.x-e.x,y:t.y-e.y});let a=Math.abs(x.x-p.x)<1e-8?r(x,{x:1,y:(x.x-p.x)/(p.y-x.y)}):r(x,{x:(p.y-x.y)/(x.x-p.x),y:1});a=s.applyToPoint(i,a),x=s.applyToPoint(i,x),p=s.applyToPoint(i,p);const o=n(a,x),c=n(p,x),l=Math.abs(o.x)<1e-8?{x:1,y:-o.x/o.y}:{x:-o.y/o.x,y:1},u=e(t(c,l)/t(l,l),l);p={x:x.x+u.x,y:x.y+u.y}}return d?(m.setAttribute("cx",Number(x.x.toFixed(4))),m.setAttribute("cy",Number(x.y.toFixed(4))),m.setAttribute("r",Number(y.toFixed(4))),w&&(m.setAttribute("fx",Number(w.x.toFixed(4))),m.setAttribute("fy",Number(w.y.toFixed(4))))):(m.setAttribute("x1",Number(x.x.toFixed(4))),m.setAttribute("y1",Number(x.y.toFixed(4))),m.setAttribute("x2",Number(p.x.toFixed(4))),m.setAttribute("y2",Number(p.y.toFixed(4)))),m.setAttribute("gradientUnits","userSpaceOnUse"),l.appendChild(m),"url(#".concat(f,")")},m=(t,e)=>{const r=t&&t.match(/\((?:["'#]*)([^"')]+)/),s=r&&r[1];return s&&e?s.replace("".concat(e.location.href.split("#")[0],"#"),""):s};t.exports=function(t,e,r){const i=s.identity(),g=(i,f,b,x,p)=>{if(function(t){return t.tagName&&u.includes(t.tagName.toLowerCase())}(i)){i.attributes["stroke-width"]&&(b=i.attributes["stroke-width"].value),i.attributes&&(i.attributes.fill&&(x=i.attributes.fill.value),i.attributes.stroke&&(p=i.attributes.stroke.value));for(let t=0;t<i.childNodes.length;t++)g(i.childNodes[t],s.compose(f,a(i)),b,x,p);i.removeAttribute("transform"),i.removeAttribute("stroke-width"),i.removeAttribute("fill"),i.removeAttribute("stroke")}else if(function(t,e){return!!t.attributes&&(e=t.attributes["stroke-width"]?Number(t.attributes["stroke-width"].value):Number(e))&&t.tagName&&"path"===t.tagName.toLowerCase()&&t.attributes.d&&t.attributes.d.value}(i,b)){if(i.attributes["stroke-width"]&&(b=i.attributes["stroke-width"].value),i.attributes.fill&&(x=i.attributes.fill.value),i.attributes.stroke&&(p=i.attributes.stroke.value),f=s.compose(f,a(i)),s.toString(f)===s.toString(s.identity()))return i.removeAttribute("transform"),i.setAttribute("stroke-width",b),x&&i.setAttribute("fill",x),void(p&&i.setAttribute("stroke",p));const l=m(x,e),u=m(p,e);if(l||u){const s=e.document,a=s.createElement("span");let o;if(r)o=r;else try{s.body.appendChild(a);const t=n.set(s.createElementNS(n.svg,"svg")),e=n.set(s.createElementNS(n.svg,"path"));e.setAttribute("d",i.attributes.d.value),t.appendChild(e),a.appendChild(t),o=t.getBBox()}finally{s.body.removeChild(a)}if(l){const e=d(l,t,o,f);e&&(x=e)}if(u){const e=d(u,t,o,f);e&&(p=e)}}i.setAttribute("d",function(t,e){if(!e||s.toString(e)===s.toString(s.identity()))return t;const r=t&&t.match(/[mlhvcsqtaz][^mlhvcsqtaz]*/gi);let n,i,a,l=!1,u={x:0,y:0},h={x:0,y:0},d="";const m=function(t,e){let r=+n[t];return l&&(r+=u[e]),r},g=function(t){return{x:m(t,"x"),y:m(t+1,"y")}},f=function(t){return Number(t.toFixed(4))},b=function(t){const r=s.applyToPoint(e,t);return"".concat(f(r.x)," ").concat(f(r.y)," ")};for(let t=0,s=r&&r.length;t<s;t++){const s=r[t],x=s[0],p=x.toLowerCase();n=s.match(/[+-]?(?:\d*\.\d+|\d+\.?)(?:[eE][+-]?\d+)?/g);const y=n&&n.length;switch(l=x===p,"z"!==i||/[mz]/.test(p)||(d+="M ".concat(u.x," ").concat(u.y," ")),p){case"m":case"l":{let t="m"===p;for(let e=0;e<y;e+=2)d+=t?"M ":"L ",u=g(e),d+=b(u),t&&(h=u,t=!1);a=u;break}case"h":case"v":{const t="h"===p?"x":"y";u={x:u.x,y:u.y};for(let e=0;e<y;e++)u[t]=m(e,t),d+="L ".concat(b(u));a=u;break}case"c":for(let t=0;t<y;t+=6){const e=g(t);a=g(t+2),u=g(t+4),d+="C ".concat(b(e)).concat(b(a)).concat(b(u))}break;case"s":for(let t=0;t<y;t+=4){const e=/[cs]/.test(i)?{x:2*u.x-a.x,y:2*u.y-a.y}:u;a=g(t),u=g(t+2),d+="C ".concat(b(e)).concat(b(a)).concat(b(u)),i=p}break;case"q":for(let t=0;t<y;t+=4)a=g(t),u=g(t+2),d+="Q ".concat(b(a)).concat(b(u));break;case"t":for(let t=0;t<y;t+=2)a=/[qt]/.test(i)?{x:2*u.x-a.x,y:2*u.y-a.y}:u,u=g(t),d+="Q ".concat(b(a)).concat(b(u)),i=p;break;case"a":for(let t=0;t<y;t+=7){u=g(t+5);const r=+n[t],s=+n[t+1],i=+n[t+2],a=+n[t+3];let l=+n[t+4];const h=c(r,s,i,e),m=o(e);h?((m.x>0&&m.y<0||m.x<0&&m.y>0)&&(l^=1),d+="A ".concat(f(Math.abs(h.radiusX))," ")+"".concat(f(Math.abs(h.radiusY))," ")+"".concat(f(h.rotation)," ").concat(a," ")+"".concat(l," ").concat(b(u))):d+="L ".concat(b(u))}break;case"z":d+="Z ",u=h}i=p}return d}(i.attributes.d.value,f)),i.removeAttribute("transform");const g=o(f);i.setAttribute("stroke-width",h(g.x,g.y)*b),x&&i.setAttribute("fill",x),p&&i.setAttribute("stroke",p)}else(function(t){return t.tagName&&l.includes(t.tagName.toLowerCase())})(i)&&(b&&!i.attributes["stroke-width"]&&i.setAttribute("stroke-width",b),x&&!i.attributes.fill&&i.setAttribute("fill",x),p&&!i.attributes.stroke&&i.setAttribute("stroke",p),f=s.compose(f,a(i)),s.toString(f)===s.toString(s.identity())?i.removeAttribute("transform"):i.setAttribute("transform",s.toString(f)))};g(t,i,1)}},88(t,e,r){const{Logger:s}=r(441);t.exports=new s({name:"scratch-svg-renderer"})},661(t){"use strict";t.exports=require("base64-js")},606(t){"use strict";t.exports=require("css-tree")},368(t){"use strict";t.exports=require("css-tree/utils")},980(t){"use strict";t.exports=require("fastestsmallesttextencoderdecoder")},975(t){"use strict";t.exports=require("isomorphic-dompurify")},770(t){"use strict";t.exports=require("scratch-render-fonts")},853(t){"use strict";t.exports=require("transformation-matrix")},441(t){"use strict";t.exports=require("tslog")}},e={},function r(s){var n=e[s];if(void 0!==n)return n.exports;var i=e[s]={exports:{}};return t[s](i,i.exports,r),i.exports}(276);var t,e});
2
2
  //# sourceMappingURL=scratch-svg-renderer.js.map