/**
 * The MIT License (MIT)
 *
 * Copyright (c) 2015-2023 yWorks GmbH
 * Copyright (c) 2013-2015 by Vitaly Puzrin
 *
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

import t,{GState as e,ShadingPattern as r,TilingPattern as i,jsPDF as n}from"./jspdf.mjs";var a=function(t,e){return(a=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])})(t,e)};function s(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function r(){this.constructor=t}a(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}var o=function(){return(o=Object.assign||function(t){for(var e,r=1,i=arguments.length;r<i;r++)for(var n in e=arguments[r])Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t}).apply(this,arguments)};function l(t,e,r,i){return new(r||(r=Promise))((function(n,a){function s(t){try{l(i.next(t))}catch(t){a(t)}}function o(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(s,o)}l((i=i.apply(t,e||[])).next())}))}function u(t,e){var r,i,n,a,s={label:0,sent:function(){if(1&n[0])throw n[1];return n[1]},trys:[],ops:[]};return a={next:o(0),throw:o(1),return:o(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function o(a){return function(o){return function(a){if(r)throw new TypeError("Generator is already executing.");for(;s;)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 s.label++,{value:a[1],done:!1};case 5:s.label++,i=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!(n=s.trys,(n=n.length>0&&n[n.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!n||a[1]>n[0]&&a[1]<n[3])){s.label=a[1];break}if(6===a[0]&&s.label<n[1]){s.label=n[1],n=a;break}if(n&&s.label<n[2]){s.label=n[2],s.ops.push(a);break}n[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}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,o])}}}var h=function(){function t(t){if(this.a=void 0,this.r=0,this.g=0,this.b=0,this.simpleColors={},this.colorDefs=[],this.ok=!1,t){for(var e in"#"==t.charAt(0)&&(t=t.substr(1,6)),t=(t=t.replace(/ /g,"")).toLowerCase(),this.simpleColors={aliceblue:"f0f8ff",antiquewhite:"faebd7",aqua:"00ffff",aquamarine:"7fffd4",azure:"f0ffff",beige:"f5f5dc",bisque:"ffe4c4",black:"000000",blanchedalmond:"ffebcd",blue:"0000ff",blueviolet:"8a2be2",brown:"a52a2a",burlywood:"deb887",cadetblue:"5f9ea0",chartreuse:"7fff00",chocolate:"d2691e",coral:"ff7f50",cornflowerblue:"6495ed",cornsilk:"fff8dc",crimson:"dc143c",cyan:"00ffff",darkblue:"00008b",darkcyan:"008b8b",darkgoldenrod:"b8860b",darkgray:"a9a9a9",darkgrey:"a9a9a9",darkgreen:"006400",darkkhaki:"bdb76b",darkmagenta:"8b008b",darkolivegreen:"556b2f",darkorange:"ff8c00",darkorchid:"9932cc",darkred:"8b0000",darksalmon:"e9967a",darkseagreen:"8fbc8f",darkslateblue:"483d8b",darkslategray:"2f4f4f",darkslategrey:"2f4f4f",darkturquoise:"00ced1",darkviolet:"9400d3",deeppink:"ff1493",deepskyblue:"00bfff",dimgray:"696969",dimgrey:"696969",dodgerblue:"1e90ff",feldspar:"d19275",firebrick:"b22222",floralwhite:"fffaf0",forestgreen:"228b22",fuchsia:"ff00ff",gainsboro:"dcdcdc",ghostwhite:"f8f8ff",gold:"ffd700",goldenrod:"daa520",gray:"808080",grey:"808080",green:"008000",greenyellow:"adff2f",honeydew:"f0fff0",hotpink:"ff69b4",indianred:"cd5c5c",indigo:"4b0082",ivory:"fffff0",khaki:"f0e68c",lavender:"e6e6fa",lavenderblush:"fff0f5",lawngreen:"7cfc00",lemonchiffon:"fffacd",lightblue:"add8e6",lightcoral:"f08080",lightcyan:"e0ffff",lightgoldenrodyellow:"fafad2",lightgray:"d3d3d3",lightgrey:"d3d3d3",lightgreen:"90ee90",lightpink:"ffb6c1",lightsalmon:"ffa07a",lightseagreen:"20b2aa",lightskyblue:"87cefa",lightslateblue:"8470ff",lightslategray:"778899",lightslategrey:"778899",lightsteelblue:"b0c4de",lightyellow:"ffffe0",lime:"00ff00",limegreen:"32cd32",linen:"faf0e6",magenta:"ff00ff",maroon:"800000",mediumaquamarine:"66cdaa",mediumblue:"0000cd",mediumorchid:"ba55d3",mediumpurple:"9370d8",mediumseagreen:"3cb371",mediumslateblue:"7b68ee",mediumspringgreen:"00fa9a",mediumturquoise:"48d1cc",mediumvioletred:"c71585",midnightblue:"191970",mintcream:"f5fffa",mistyrose:"ffe4e1",moccasin:"ffe4b5",navajowhite:"ffdead",navy:"000080",oldlace:"fdf5e6",olive:"808000",olivedrab:"6b8e23",orange:"ffa500",orangered:"ff4500",orchid:"da70d6",palegoldenrod:"eee8aa",palegreen:"98fb98",paleturquoise:"afeeee",palevioletred:"d87093",papayawhip:"ffefd5",peachpuff:"ffdab9",peru:"cd853f",pink:"ffc0cb",plum:"dda0dd",powderblue:"b0e0e6",purple:"800080",red:"ff0000",rosybrown:"bc8f8f",royalblue:"4169e1",saddlebrown:"8b4513",salmon:"fa8072",sandybrown:"f4a460",seagreen:"2e8b57",seashell:"fff5ee",sienna:"a0522d",silver:"c0c0c0",skyblue:"87ceeb",slateblue:"6a5acd",slategray:"708090",slategrey:"708090",snow:"fffafa",springgreen:"00ff7f",steelblue:"4682b4",tan:"d2b48c",teal:"008080",thistle:"d8bfd8",tomato:"ff6347",turquoise:"40e0d0",violet:"ee82ee",violetred:"d02090",wheat:"f5deb3",white:"ffffff",whitesmoke:"f5f5f5",yellow:"ffff00",yellowgreen:"9acd32"},this.simpleColors)t==e&&(t=this.simpleColors[e]);this.colorDefs=[{re:/^rgb\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)$/,example:["rgb(123, 234, 45)","rgb(255,234,245)"],process:function(t){return[parseInt(t[1]),parseInt(t[2]),parseInt(t[3])]}},{re:/^(\w{2})(\w{2})(\w{2})$/,example:["#00ff00","336699"],process:function(t){return[parseInt(t[1],16),parseInt(t[2],16),parseInt(t[3],16)]}},{re:/^(\w{1})(\w{1})(\w{1})$/,example:["#fb0","f0f"],process:function(t){return[parseInt(t[1]+t[1],16),parseInt(t[2]+t[2],16),parseInt(t[3]+t[3],16)]}}];for(var r=0;r<this.colorDefs.length;r++){var i=this.colorDefs[r].re,n=this.colorDefs[r].process,a=i.exec(t);if(a){var s=n(a);this.r=s[0],this.g=s[1],this.b=s[2],this.ok=!0}}this.r=this.r<0||isNaN(this.r)?0:this.r>255?255:this.r,this.g=this.g<0||isNaN(this.g)?0:this.g>255?255:this.g,this.b=this.b<0||isNaN(this.b)?0:this.b>255?255:this.b}}return t.prototype.toRGB=function(){return"rgb("+this.r+", "+this.g+", "+this.b+")"},t.prototype.toRGBA=function(){return"rgba("+this.r+", "+this.g+", "+this.b+", "+(this.a||"1")+")"},t.prototype.toHex=function(){var t=this.r.toString(16),e=this.g.toString(16),r=this.b.toString(16);return 1==t.length&&(t="0"+t),1==e.length&&(e="0"+e),1==r.length&&(r="0"+r),"#"+t+e+r},t.prototype.getHelpXML=function(){for(var e=[],r=0;r<this.colorDefs.length;r++)for(var i=this.colorDefs[r].example,n=0;n<i.length;n++)e[e.length]=i[n];for(var a in this.simpleColors)e[e.length]=a;var s=document.createElement("ul");s.setAttribute("id","rgbcolor-examples");for(r=0;r<e.length;r++)try{var o=document.createElement("li"),l=new t(e[r]),u=document.createElement("div");u.style.cssText="margin: 3px; border: 1px solid black; background:"+l.toHex()+"; color:"+l.toHex(),u.appendChild(document.createTextNode("test"));var h=document.createTextNode(" "+e[r]+" -> "+l.toRGB()+" -> "+l.toHex());o.appendChild(u),o.appendChild(h),s.appendChild(o)}catch(t){}return s},t}(),f=function(){function t(t){this.color=t}return t.prototype.getFillData=function(t,e){return l(this,void 0,void 0,(function(){return u(this,(function(t){return[2,void 0]}))}))},t}(),c=function(){function t(){this.xmlSpace="",this.fill=null,this.fillOpacity=1,this.fontFamily="",this.fontSize=16,this.fontStyle="",this.fontWeight="",this.opacity=1,this.stroke=null,this.strokeDasharray=null,this.strokeDashoffset=0,this.strokeLinecap="",this.strokeLinejoin="",this.strokeMiterlimit=4,this.strokeOpacity=1,this.strokeWidth=1,this.alignmentBaseline="",this.textAnchor="",this.visibility="",this.color=null}return t.prototype.clone=function(){var e=new t;return e.xmlSpace=this.xmlSpace,e.fill=this.fill,e.fillOpacity=this.fillOpacity,e.fontFamily=this.fontFamily,e.fontSize=this.fontSize,e.fontStyle=this.fontStyle,e.fontWeight=this.fontWeight,e.opacity=this.opacity,e.stroke=this.stroke,e.strokeDasharray=this.strokeDasharray,e.strokeDashoffset=this.strokeDashoffset,e.strokeLinecap=this.strokeLinecap,e.strokeLinejoin=this.strokeLinejoin,e.strokeMiterlimit=this.strokeMiterlimit,e.strokeOpacity=this.strokeOpacity,e.strokeWidth=this.strokeWidth,e.textAnchor=this.textAnchor,e.alignmentBaseline=this.alignmentBaseline,e.visibility=this.visibility,e.color=this.color,e},t.default=function(){var e=new t;return e.xmlSpace="default",e.fill=new f(new h("rgb(0, 0, 0)")),e.fillOpacity=1,e.fontFamily="times",e.fontSize=16,e.fontStyle="normal",e.fontWeight="normal",e.opacity=1,e.stroke=null,e.strokeDasharray=null,e.strokeDashoffset=0,e.strokeLinecap="butt",e.strokeLinejoin="miter",e.strokeMiterlimit=4,e.strokeOpacity=1,e.strokeWidth=1,e.alignmentBaseline="baseline",e.textAnchor="start",e.visibility="visible",e.color=new h("rgb(0, 0, 0)"),e},t}(),p=function(){function t(t,e){var r,i,n;this.pdf=t,this.svg2pdfParameters=e.svg2pdfParameters,this.attributeState=e.attributeState?e.attributeState.clone():c.default(),this.viewport=e.viewport,this.refsHandler=e.refsHandler,this.styleSheets=e.styleSheets,this.textMeasure=e.textMeasure,this.transform=null!==(r=e.transform)&&void 0!==r?r:this.pdf.unitMatrix,this.withinClipPath=null!==(i=e.withinClipPath)&&void 0!==i&&i,this.withinUse=null!==(n=e.withinUse)&&void 0!==n&&n}return t.prototype.clone=function(e){var r,i,n,a;return void 0===e&&(e={}),new t(this.pdf,{svg2pdfParameters:this.svg2pdfParameters,attributeState:e.attributeState?e.attributeState.clone():this.attributeState.clone(),viewport:null!==(r=e.viewport)&&void 0!==r?r:this.viewport,refsHandler:this.refsHandler,styleSheets:this.styleSheets,textMeasure:this.textMeasure,transform:null!==(i=e.transform)&&void 0!==i?i:this.transform,withinClipPath:null!==(n=e.withinClipPath)&&void 0!==n?n:this.withinClipPath,withinUse:null!==(a=e.withinUse)&&void 0!==a?a:this.withinUse})},t}(),d=function(){function t(e){this.renderedElements={},this.idMap=e,this.idPrefix=String(t.instanceCounter++)}return t.prototype.getRendered=function(t,e,r){return l(this,void 0,void 0,(function(){var i,n;return u(this,(function(a){switch(a.label){case 0:return i=this.generateKey(t,e),this.renderedElements.hasOwnProperty(i)?[2,this.renderedElements[t]]:(n=this.get(t),this.renderedElements[i]=n,[4,r(n)]);case 1:return a.sent(),[2,n]}}))}))},t.prototype.get=function(t){return this.idMap[t]},t.prototype.generateKey=function(t,e){return this.idPrefix+"|"+t+"|"+(e||new h("rgb(0,0,0)")).toRGBA()},t.instanceCounter=0,t}();function m(t,e){return Math.atan2(e[1]-t[1],e[0]-t[0])}function g(t,e){return[2/3*(e[0]-t[0])+t[0],2/3*(e[1]-t[1])+t[1]]}function v(t){var e=Math.sqrt(t[0]*t[0]+t[1]*t[1]);return[t[0]/e,t[1]/e]}function y(t,e){return v([e[0]-t[0],e[1]-t[1]])}function b(t,e){return[t[0]+e[0],t[1]+e[1]]}function x(t,e){var r=t[0],i=t[1];return[e.a*r+e.c*i+e.e,e.b*r+e.d*i+e.f]}var S=function(){function t(){this.segments=[]}return t.prototype.moveTo=function(t,e){return this.segments.push(new w(t,e)),this},t.prototype.lineTo=function(t,e){return this.segments.push(new k(t,e)),this},t.prototype.curveTo=function(t,e,r,i,n,a){return this.segments.push(new M(t,e,r,i,n,a)),this},t.prototype.close=function(){return this.segments.push(new C),this},t.prototype.transform=function(t){this.segments.forEach((function(e){if(e instanceof w||e instanceof k||e instanceof M){var r=x([e.x,e.y],t);e.x=r[0],e.y=r[1]}if(e instanceof M){var i=x([e.x1,e.y1],t),n=x([e.x2,e.y2],t);e.x1=i[0],e.y1=i[1],e.x2=n[0],e.y2=n[1]}}))},t.prototype.draw=function(t){var e=t.pdf;this.segments.forEach((function(t){t instanceof w?e.moveTo(t.x,t.y):t instanceof k?e.lineTo(t.x,t.y):t instanceof M?e.curveTo(t.x1,t.y1,t.x2,t.y2,t.x,t.y):e.close()}))},t}(),w=function(t,e){this.x=t,this.y=e},k=function(t,e){this.x=t,this.y=e},M=function(t,e,r,i,n,a){this.x1=t,this.y1=e,this.x2=r,this.y2=i,this.x=n,this.y=a},C=function(){};function F(t,e){return e.split(",").indexOf((t.nodeName||t.tagName).toLowerCase())>=0}function T(t,e,r,i){var n;void 0===i&&(i=r);var a=null===(n=t.style)||void 0===n?void 0:n.getPropertyValue(i);if(a)return a;var s=e.getPropertyValue(t,i);return s||(t.hasAttribute(r)&&t.getAttribute(r)||void 0)}function A(t,e,r){if("none"===T(t.element,r.styleSheets,"display"))return!1;var i=e,n=T(t.element,r.styleSheets,"visibility");return n&&(i="hidden"!==n),i}function P(t,e,r){var i=A(t,e,r);return 0!==t.element.childNodes.length&&(t.children.forEach((function(t){t.isVisible(i,r)&&(i=!0)})),i)}var B=function(){function t(){this.markers=[]}return t.prototype.addMarker=function(t){this.markers.push(t)},t.prototype.draw=function(t){return l(this,void 0,void 0,(function(){var e,r,i,n,a,s,o;return u(this,(function(l){switch(l.label){case 0:e=0,l.label=1;case 1:return e<this.markers.length?(r=this.markers[e],i=void 0,n=r.angle,a=r.anchor,s=Math.cos(n),o=Math.sin(n),i=t.pdf.Matrix(s,o,-o,s,a[0],a[1]),i=t.pdf.matrixMult(t.pdf.Matrix(t.attributeState.strokeWidth,0,0,t.attributeState.strokeWidth,0,0),i),i=t.pdf.matrixMult(i,t.transform),t.pdf.saveGraphicsState(),[4,t.refsHandler.getRendered(r.id,null,(function(e){return e.apply(t)}))]):[3,4];case 2:l.sent(),t.pdf.doFormObject(r.id,i),t.pdf.restoreGraphicsState(),l.label=3;case 3:return e++,[3,1];case 4:return[2]}}))}))},t}(),N=function(t,e,r){this.id=t,this.anchor=e,this.angle=r},E=/url\(["']?#([^"']+)["']?\)/,L={bottom:"bottom","text-bottom":"bottom",top:"top","text-top":"top",hanging:"hanging",middle:"middle",central:"middle",center:"middle",mathematical:"middle",ideographic:"ideographic",alphabetic:"alphabetic",baseline:"alphabetic"};function O(t,e){var r;return(r=t&&t.toString().match(/^([\-0-9.]+)em$/))?parseFloat(r[1])*e:(r=t&&t.toString().match(/^([\-0-9.]+)(px|)$/))?parseFloat(r[1]):0}function _(t){return L[t]||"alphabetic"}function I(t){for(var e,r=[],i=/[+-]?(?:(?:\d+\.?\d*)|(?:\d*\.?\d+))(?:[eE][+-]?\d+)?/g;e=i.exec(t);)r.push(parseFloat(e[0]));return r}function H(t,e){if("transparent"===t){var r=new h("rgb(0,0,0)");return r.a=0,r}if("currentcolor"===t.toLowerCase())return e||new h("rgb(0,0,0)");var i=/\s*rgba\(((?:[^,\)]*,){3}[^,\)]*)\)\s*/.exec(t);if(i){var n=I(i[1]),a=new h("rgb("+n.slice(0,3).join(",")+")");return a.a=n[3],a}return new h(t)}var D=/[a-z0-9_-]/i,V=/[\s\t]/,R=function(t){for(var e,r,i=!0,n=0,a="",s=0,o=[];;){if(r=t[s],0===n){if(!r&&i)break;if(!r&&!i)throw new Error("Parse error");if('"'===r||"'"===r)e=r,n=1,i=!1;else if(V.test(r));else{if(!D.test(r))throw new Error("Parse error");n=3,i=!1,s--}}else if(1===n){if(!r)throw new Error("Parse Error");"\\"===r?n=2:r===e?(o.push(a),a="",n=4):a+=r}else if(2===n){if(r!==e&&"\\"!==r)throw new Error("Parse error");a+=r,n=1}else if(3===n){if(!r){o.push(a);break}if(D.test(r))a+=r;else if(","===r)o.push(a),a="",n=0;else{if(!V.test(r))throw new Error("Parse error");n=5}}else if(5===n){if(!r){o.push(a);break}if(D.test(r))a+=" "+r,n=3;else if(","===r)o.push(a),a="",n=0;else if(!V.test(r))throw new Error("Parse error")}else if(4===n){if(!r)break;if(","===r)n=0;else if(!V.test(r))throw new Error("Parse error")}s++}return o},W={"sans-serif":"helvetica",verdana:"helvetica",arial:"helvetica",fixed:"courier",monospace:"courier",terminal:"courier",serif:"times",cursive:"times",fantasy:"times"};var q,j=(q=t.version.split("."),2===parseFloat(q[0])&&3===parseFloat(q[1]));function G(t,e){return j?400==e?"italic"==t?"italic":"normal":700==e&&"italic"!==t?"bold":t+""+e:400==e||"normal"===e?"italic"===t?"italic":"normal":700!=e&&"bold"!==e||"normal"!==t?(700==e?"bold":e)+""+t:"bold"}function U(t,e){if("none"===T(e.element,t.styleSheets,"display"))return[0,0,0,0];var r=[0,0,0,0];return e.children.forEach((function(e){var i=e.getBoundingBox(t);r=[Math.min(r[0],i[0]),Math.min(r[1],i[1]),Math.max(r[0]+r[2],i[0]+i[2])-Math.min(r[0],i[0]),Math.max(r[1]+r[3],i[1]+i[3])-Math.min(r[1],i[1])]})),r}function z(t,e){var r=parseFloat,i=r(t.getAttribute("x1"))||r(T(t,e.styleSheets,"x"))||r(T(t,e.styleSheets,"cx"))-r(T(t,e.styleSheets,"r"))||0,n=r(t.getAttribute("x2"))||i+r(T(t,e.styleSheets,"width"))||r(T(t,e.styleSheets,"cx"))+r(T(t,e.styleSheets,"r"))||0,a=r(t.getAttribute("y1"))||r(T(t,e.styleSheets,"y"))||r(T(t,e.styleSheets,"cy"))-r(T(t,e.styleSheets,"r"))||0,s=r(t.getAttribute("y2"))||a+r(T(t,e.styleSheets,"height"))||r(T(t,e.styleSheets,"cy"))+r(T(t,e.styleSheets,"r"))||0;return[Math.min(i,n),Math.min(a,s),Math.max(i,n)-Math.min(i,n),Math.max(a,s)-Math.min(a,s)]}function Y(t,e,r,i,n,a,s,o){void 0===o&&(o=!1);var l,u,h=e[0],f=e[1],c=e[2],p=e[3],d=n/c,m=a/p,g=t.getAttribute("preserveAspectRatio");if(g){var v=g.split(" ");"defer"===v[0]&&(v=v.slice(1)),l=v[0],u=v[1]||"meet"}else l="xMidYMid",u="meet";if("none"!==l&&("meet"===u?d=m=Math.min(d,m):"slice"===u&&(d=m=Math.max(d,m))),o)return s.pdf.Matrix(d,0,0,m,0,0);var y=r-h*d,b=i-f*m;l.indexOf("xMid")>=0?y+=(n-c*d)/2:l.indexOf("xMax")>=0&&(y+=n-c*d),l.indexOf("YMid")>=0?b+=(a-p*m)/2:l.indexOf("YMax")>=0&&(b+=a-p*m);var x=s.pdf.Matrix(1,0,0,1,y,b),S=s.pdf.Matrix(d,0,0,m,0,0);return s.pdf.matrixMult(S,x)}function X(t,e){if(!t||"none"===t)return e.pdf.unitMatrix;for(var r,i,n=/^[\s,]*matrix\(([^)]+)\)\s*/,a=/^[\s,]*translate\(([^)]+)\)\s*/,s=/^[\s,]*rotate\(([^)]+)\)\s*/,o=/^[\s,]*scale\(([^)]+)\)\s*/,l=/^[\s,]*skewX\(([^)]+)\)\s*/,u=/^[\s,]*skewY\(([^)]+)\)\s*/,h=e.pdf.unitMatrix;t.length>0&&t.length!==i;){i=t.length;var f=n.exec(t);if(f&&(r=I(f[1]),h=e.pdf.matrixMult(e.pdf.Matrix(r[0],r[1],r[2],r[3],r[4],r[5]),h),t=t.substr(f[0].length)),f=s.exec(t)){r=I(f[1]);var c=Math.PI*r[0]/180;if(h=e.pdf.matrixMult(e.pdf.Matrix(Math.cos(c),Math.sin(c),-Math.sin(c),Math.cos(c),0,0),h),r[1]||r[2]){var p=e.pdf.Matrix(1,0,0,1,r[1],r[2]),d=e.pdf.Matrix(1,0,0,1,-r[1],-r[2]);h=e.pdf.matrixMult(d,e.pdf.matrixMult(h,p))}t=t.substr(f[0].length)}(f=a.exec(t))&&(r=I(f[1]),h=e.pdf.matrixMult(e.pdf.Matrix(1,0,0,1,r[0],r[1]||0),h),t=t.substr(f[0].length)),(f=o.exec(t))&&((r=I(f[1]))[1]||(r[1]=r[0]),h=e.pdf.matrixMult(e.pdf.Matrix(r[0],0,0,r[1],0,0),h),t=t.substr(f[0].length)),(f=l.exec(t))&&(r=parseFloat(f[1]),r*=Math.PI/180,h=e.pdf.matrixMult(e.pdf.Matrix(1,0,Math.tan(r),1,0,0),h),t=t.substr(f[0].length)),(f=u.exec(t))&&(r=parseFloat(f[1]),r*=Math.PI/180,h=e.pdf.matrixMult(e.pdf.Matrix(1,Math.tan(r),0,1,0,0),h),t=t.substr(f[0].length))}return h}var Q=function(){function t(t,e){this.element=t,this.children=e,this.parent=null}return t.prototype.setParent=function(t){this.parent=t},t.prototype.getParent=function(){return this.parent},t.prototype.getBoundingBox=function(t){return"none"===T(this.element,t.styleSheets,"display")?[0,0,0,0]:this.getBoundingBoxCore(t)},t.prototype.computeNodeTransform=function(t){var e=this.computeNodeTransformCore(t),r=T(this.element,t.styleSheets,"transform");return r?t.pdf.matrixMult(e,X(r,t)):e},t}(),$=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return s(e,t),e.prototype.render=function(t){return Promise.resolve()},e.prototype.getBoundingBoxCore=function(t){return[]},e.prototype.computeNodeTransformCore=function(t){return t.pdf.unitMatrix},e}(Q),K=function(t){function i(e,r,i){var n=t.call(this,r,i)||this;return n.pdfGradientType=e,n.contextColor=void 0,n}return s(i,t),i.prototype.apply=function(t){return l(this,void 0,void 0,(function(){var i,n,a,s,o,l;return u(this,(function(u){return(i=this.element.getAttribute("id"))?(n=this.getStops(t.styleSheets),a=0,s=!1,n.forEach((function(t){var e=t.opacity;e&&1!==e&&(a+=e,s=!0)})),s&&(o=new e({opacity:a/n.length})),l=new r(this.pdfGradientType,this.getCoordinates(),n,o),t.pdf.addShadingPattern(i,l),[2]):[2]}))}))},i.prototype.getStops=function(t){var e=this;if(this.stops)return this.stops;if(void 0===this.contextColor){this.contextColor=null;for(var r=this;r;){var n=T(r.element,t,"color");if(n){this.contextColor=H(n,null);break}r=r.getParent()}}var a=[];return this.children.forEach((function(r){if("stop"===r.element.tagName.toLowerCase()){var n=T(r.element,t,"color"),s=H(T(r.element,t,"stop-color")||"",n?H(n,null):e.contextColor),o=parseFloat(T(r.element,t,"stop-opacity")||"1");a.push({offset:i.parseGradientOffset(r.element.getAttribute("offset")||"0"),color:[s.r,s.g,s.b],opacity:o})}})),this.stops=a},i.prototype.getBoundingBoxCore=function(t){return z(this.element,t)},i.prototype.computeNodeTransformCore=function(t){return t.pdf.unitMatrix},i.prototype.isVisible=function(t,e){return P(this,t,e)},i.parseGradientOffset=function(t){var e=parseFloat(t);return!isNaN(e)&&t.indexOf("%")>=0?e/100:e},i}($),Z=function(t){function e(e,r){return t.call(this,"axial",e,r)||this}return s(e,t),e.prototype.getCoordinates=function(){return[parseFloat(this.element.getAttribute("x1")||"0"),parseFloat(this.element.getAttribute("y1")||"0"),parseFloat(this.element.getAttribute("x2")||"1"),parseFloat(this.element.getAttribute("y2")||"0")]},e}(K),J=function(t){function e(e,r){return t.call(this,"radial",e,r)||this}return s(e,t),e.prototype.getCoordinates=function(){var t=this.element.getAttribute("cx"),e=this.element.getAttribute("cy"),r=this.element.getAttribute("fx"),i=this.element.getAttribute("fy");return[parseFloat(r||t||"0.5"),parseFloat(i||e||"0.5"),0,parseFloat(t||"0.5"),parseFloat(e||"0.5"),parseFloat(this.element.getAttribute("r")||"0.5")]},e}(K),tt=function(){function t(t,e){this.key=t,this.gradient=e}return t.prototype.getFillData=function(t,e){return l(this,void 0,void 0,(function(){var r,i,n;return u(this,(function(a){switch(a.label){case 0:return[4,e.refsHandler.getRendered(this.key,null,(function(t){return t.apply(new p(e.pdf,{refsHandler:e.refsHandler,textMeasure:e.textMeasure,styleSheets:e.styleSheets,viewport:e.viewport,svg2pdfParameters:e.svg2pdfParameters}))}))];case 1:return a.sent(),this.gradient.element.hasAttribute("gradientUnits")&&"objectboundingbox"!==this.gradient.element.getAttribute("gradientUnits").toLowerCase()?r=e.pdf.unitMatrix:(i=t.getBoundingBox(e),r=e.pdf.Matrix(i[2],0,0,i[3],i[0],i[1])),n=X(T(this.gradient.element,e.styleSheets,"gradientTransform","transform"),e),[2,{key:this.key,matrix:e.pdf.matrixMult(n,r)}]}}))}))},t}(),et=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return s(e,t),e.prototype.apply=function(t){return l(this,void 0,void 0,(function(){var e,r,n,a,s;return u(this,(function(o){switch(o.label){case 0:if(!(e=this.element.getAttribute("id")))return[2];r=this.getBoundingBox(t),n=new i([r[0],r[1],r[0]+r[2],r[1]+r[3]],r[2],r[3]),t.pdf.beginTilingPattern(n),a=0,s=this.children,o.label=1;case 1:return a<s.length?[4,s[a].render(new p(t.pdf,{attributeState:t.attributeState,refsHandler:t.refsHandler,styleSheets:t.styleSheets,viewport:t.viewport,svg2pdfParameters:t.svg2pdfParameters,textMeasure:t.textMeasure}))]:[3,4];case 2:o.sent(),o.label=3;case 3:return a++,[3,1];case 4:return t.pdf.endTilingPattern(e,n),[2]}}))}))},e.prototype.getBoundingBoxCore=function(t){return z(this.element,t)},e.prototype.computeNodeTransformCore=function(t){return t.pdf.unitMatrix},e.prototype.isVisible=function(t,e){return P(this,t,e)},e}($),rt=function(){function t(t,e){this.key=t,this.pattern=e}return t.prototype.getFillData=function(t,e){return l(this,void 0,void 0,(function(){var r,i,n,a,s,o,l,h,f,c,d,m;return u(this,(function(u){switch(u.label){case 0:return[4,e.refsHandler.getRendered(this.key,null,(function(t){return t.apply(new p(e.pdf,{refsHandler:e.refsHandler,textMeasure:e.textMeasure,styleSheets:e.styleSheets,viewport:e.viewport,svg2pdfParameters:e.svg2pdfParameters}))}))];case 1:return u.sent(),r={key:this.key,boundingBox:void 0,xStep:0,yStep:0,matrix:void 0},n=e.pdf.unitMatrix,this.pattern.element.hasAttribute("patternUnits")&&"objectboundingbox"!==this.pattern.element.getAttribute("patternUnits").toLowerCase()||(i=t.getBoundingBox(e),n=e.pdf.Matrix(1,0,0,1,i[0],i[1]),s=this.pattern.getBoundingBox(e),o=s[0]*i[0]||0,l=s[1]*i[1]||0,h=s[2]*i[2]||0,f=s[3]*i[3]||0,r.boundingBox=[o,l,o+h,l+f],r.xStep=h,r.yStep=f),a=e.pdf.unitMatrix,this.pattern.element.hasAttribute("patternContentUnits")&&"objectboundingbox"===this.pattern.element.getAttribute("patternContentUnits").toLowerCase()&&(i||(i=t.getBoundingBox(e)),a=e.pdf.Matrix(i[2],0,0,i[3],0,0),s=r.boundingBox||this.pattern.getBoundingBox(e),o=s[0]/i[0]||0,l=s[1]/i[1]||0,h=s[2]/i[2]||0,f=s[3]/i[3]||0,r.boundingBox=[o,l,o+h,l+f],r.xStep=h,r.yStep=f),c=e.pdf.unitMatrix,(d=T(this.pattern.element,e.styleSheets,"patternTransform","transform"))&&(c=X(d,e)),m=a,m=e.pdf.matrixMult(m,n),m=e.pdf.matrixMult(m,c),m=e.pdf.matrixMult(m,e.transform),r.matrix=m,[2,r]}}))}))},t}();function it(t,e){var r=E.exec(t);if(r){var i=r[1],n=e.refsHandler.get(i);return n&&(n instanceof Z||n instanceof J)?function(t,e,r){var i=e.getStops(r.styleSheets);if(0===i.length)return null;if(1===i.length){var n=i[0].color,a=new h;return a.ok=!0,a.r=n[0],a.g=n[1],a.b=n[2],a.a=i[0].opacity,new f(a)}return new tt(t,e)}(i,n,e):n&&n instanceof et?new rt(i,n):new f(new h("rgb(0, 0, 0)"))}var a=H(t,e.attributeState.color);return a.ok?new f(a):null}function nt(t,e,r){var i=r||e.element,n=T(i,t.styleSheets,"color");if(n){var a=H(n,t.attributeState.color);a.ok?t.attributeState.color=a:t.attributeState.color=new h("rgb(0,0,0)")}var s=T(i,t.styleSheets,"visibility");s&&(t.attributeState.visibility=s);var o=T(i,t.styleSheets,"fill");o&&(t.attributeState.fill=it(o,t));var l=T(i,t.styleSheets,"fill-opacity");l&&(t.attributeState.fillOpacity=parseFloat(l));var u=T(i,t.styleSheets,"stroke-opacity");u&&(t.attributeState.strokeOpacity=parseFloat(u));var c=T(i,t.styleSheets,"opacity");c&&(t.attributeState.opacity=parseFloat(c));var p=T(i,t.styleSheets,"stroke-width");void 0!==p&&""!==p&&(t.attributeState.strokeWidth=Math.abs(parseFloat(p)));var d=T(i,t.styleSheets,"stroke");if(d)if("none"===d)t.attributeState.stroke=null;else{var m=H(d,t.attributeState.color);m.ok&&(t.attributeState.stroke=new f(m))}var g=T(i,t.styleSheets,"stroke-linecap");g&&(t.attributeState.strokeLinecap=g);var v=T(i,t.styleSheets,"stroke-linejoin");v&&(t.attributeState.strokeLinejoin=v);var y=T(i,t.styleSheets,"stroke-dasharray");if(y){var b=parseInt(T(i,t.styleSheets,"stroke-dashoffset")||"0");t.attributeState.strokeDasharray=I(y),t.attributeState.strokeDashoffset=b}var x=T(i,t.styleSheets,"stroke-miterlimit");void 0!==x&&""!==x&&(t.attributeState.strokeMiterlimit=parseFloat(x));var S=i.getAttribute("xml:space");S&&(t.attributeState.xmlSpace=S);var w=T(i,t.styleSheets,"font-weight");w&&(t.attributeState.fontWeight=w);var k=T(i,t.styleSheets,"font-style");k&&(t.attributeState.fontStyle=k);var M=T(i,t.styleSheets,"font-family");if(M){var C=R(M);t.attributeState.fontFamily=function(t,e,r){var i=G(t.fontStyle,t.fontWeight),n=r.pdf.getFontList(),a="";return e.some((function(t){var e=n[t];return e&&e.indexOf(i)>=0?(a=t,!0):(t=t.toLowerCase(),!!W.hasOwnProperty(t)&&(a=t,!0))}))||(a="times"),a}(t.attributeState,C,t)}var F=T(i,t.styleSheets,"font-size");if(F){var A=t.pdf.getFontSize();t.attributeState.fontSize=O(F,A)}var P=T(i,t.styleSheets,"vertical-align")||T(i,t.styleSheets,"alignment-baseline");if(P){var B=P.match(/(baseline|text-bottom|alphabetic|ideographic|middle|central|mathematical|text-top|bottom|center|top|hanging)/);B&&(t.attributeState.alignmentBaseline=B[0])}var N=T(i,t.styleSheets,"text-anchor");N&&(t.attributeState.textAnchor=N)}function at(t,r,i){var n=1,a=1;n*=t.attributeState.fillOpacity,n*=t.attributeState.opacity,t.attributeState.fill instanceof f&&void 0!==t.attributeState.fill.color.a&&(n*=t.attributeState.fill.color.a),a*=t.attributeState.strokeOpacity,a*=t.attributeState.opacity,t.attributeState.stroke instanceof f&&void 0!==t.attributeState.stroke.color.a&&(a*=t.attributeState.stroke.color.a);var s,o,l=n<1,u=a<1;if(F(i,"use")?(l=!0,u=!0,n*=t.attributeState.fill?1:0,a*=t.attributeState.stroke?1:0):t.withinUse&&(t.attributeState.fill!==r.attributeState.fill?(l=!0,n*=t.attributeState.fill?1:0):l&&!t.attributeState.fill&&(n=0),t.attributeState.stroke!==r.attributeState.stroke?(u=!0,a*=t.attributeState.stroke?1:0):u&&!t.attributeState.stroke&&(a=0)),l||u){var h={};l&&(h.opacity=n),u&&(h["stroke-opacity"]=a),t.pdf.setGState(new e(h))}if(t.attributeState.fill&&t.attributeState.fill!==r.attributeState.fill&&t.attributeState.fill instanceof f&&t.attributeState.fill.color.ok&&!F(i,"text")&&t.pdf.setFillColor(t.attributeState.fill.color.r,t.attributeState.fill.color.g,t.attributeState.fill.color.b),t.attributeState.strokeWidth!==r.attributeState.strokeWidth&&t.pdf.setLineWidth(t.attributeState.strokeWidth),t.attributeState.stroke!==r.attributeState.stroke&&t.attributeState.stroke instanceof f&&t.pdf.setDrawColor(t.attributeState.stroke.color.r,t.attributeState.stroke.color.g,t.attributeState.stroke.color.b),t.attributeState.strokeLinecap!==r.attributeState.strokeLinecap&&t.pdf.setLineCap(t.attributeState.strokeLinecap),t.attributeState.strokeLinejoin!==r.attributeState.strokeLinejoin&&t.pdf.setLineJoin(t.attributeState.strokeLinejoin),t.attributeState.strokeDasharray===r.attributeState.strokeDasharray&&t.attributeState.strokeDashoffset===r.attributeState.strokeDashoffset||!t.attributeState.strokeDasharray||t.pdf.setLineDashPattern(t.attributeState.strokeDasharray,t.attributeState.strokeDashoffset),t.attributeState.strokeMiterlimit!==r.attributeState.strokeMiterlimit&&t.pdf.setLineMiterLimit(t.attributeState.strokeMiterlimit),t.attributeState.fontFamily!==r.attributeState.fontFamily&&(s=W.hasOwnProperty(t.attributeState.fontFamily)?W[t.attributeState.fontFamily]:t.attributeState.fontFamily),t.attributeState.fill&&t.attributeState.fill!==r.attributeState.fill&&t.attributeState.fill instanceof f&&t.attributeState.fill.color.ok){var c=t.attributeState.fill.color;t.pdf.setTextColor(c.r,c.g,c.b)}t.attributeState.fontWeight===r.attributeState.fontWeight&&t.attributeState.fontStyle===r.attributeState.fontStyle||(o=G(t.attributeState.fontStyle,t.attributeState.fontWeight)),void 0===s&&void 0===o||(void 0===s&&(s=W.hasOwnProperty(t.attributeState.fontFamily)?W[t.attributeState.fontFamily]:t.attributeState.fontFamily),t.pdf.setFont(s,o)),t.attributeState.fontSize!==r.attributeState.fontSize&&t.pdf.setFontSize(t.attributeState.fontSize*t.pdf.internal.scaleFactor)}function st(t,e,r){var i=E.exec(t);if(i){var n=i[1];return r.refsHandler.get(n)||void 0}}function ot(t,e,r){return l(this,void 0,void 0,(function(){var i,n;return u(this,(function(a){switch(a.label){case 0:return i=r.clone(),e.element.hasAttribute("clipPathUnits")&&"objectboundingbox"===e.element.getAttribute("clipPathUnits").toLowerCase()&&(n=t.getBoundingBox(r),i.transform=r.pdf.matrixMult(r.pdf.Matrix(n[2],0,0,n[3],n[0],n[1]),r.transform)),[4,e.apply(i)];case 1:return a.sent(),[2]}}))}))}var lt=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return s(e,t),e.prototype.render=function(t){return l(this,void 0,void 0,(function(){var e,r,i,n;return u(this,(function(a){switch(a.label){case 0:return this.isVisible("hidden"!==t.attributeState.visibility,t)?((e=t.clone()).transform=e.pdf.matrixMult(this.computeNodeTransform(e),t.transform),nt(e,this),r=T(this.element,e.styleSheets,"clip-path"),(i=r&&"none"!==r)?(n=st(r,0,e))?n.isVisible(!0,e)?(e.pdf.saveGraphicsState(),[4,ot(this,n,e)]):[3,2]:[3,4]:[3,5]):[2];case 1:return a.sent(),[3,3];case 2:return[2];case 3:return[3,5];case 4:i=!1,a.label=5;case 5:return e.withinClipPath||e.pdf.saveGraphicsState(),at(e,t,this.element),[4,this.renderCore(e)];case 6:return a.sent(),e.withinClipPath||e.pdf.restoreGraphicsState(),i&&e.pdf.restoreGraphicsState(),[2]}}))}))},e}(Q),ut=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return s(e,t),e}(lt),ht=function(t){function e(e,r,i){var n=t.call(this,r,i)||this;return n.cachedPath=null,n.hasMarkers=e,n}return s(e,t),e.prototype.renderCore=function(t){return l(this,void 0,void 0,(function(){var e;return u(this,(function(r){switch(r.label){case 0:return null===(e=this.getCachedPath(t))||0===e.segments.length?[2]:(t.withinClipPath?e.transform(t.transform):t.pdf.setCurrentTransformationMatrix(t.transform),e.draw(t),[4,this.fillOrStroke(t)]);case 1:return r.sent(),this.hasMarkers?[4,this.drawMarkers(t,e)]:[3,3];case 2:r.sent(),r.label=3;case 3:return[2]}}))}))},e.prototype.getCachedPath=function(t){return this.cachedPath||(this.cachedPath=this.getPath(t))},e.prototype.drawMarkers=function(t,e){return l(this,void 0,void 0,(function(){return u(this,(function(r){switch(r.label){case 0:return[4,this.getMarkers(e,t).draw(t.clone({transform:t.pdf.unitMatrix}))];case 1:return r.sent(),[2]}}))}))},e.prototype.fillOrStroke=function(t){return l(this,void 0,void 0,(function(){var e,r,i,n,a;return u(this,(function(s){switch(s.label){case 0:return t.withinClipPath?[2]:(e=t.attributeState.fill,r=t.attributeState.stroke&&0!==t.attributeState.strokeWidth,e?[4,e.getFillData(this,t)]:[3,2]);case 1:return n=s.sent(),[3,3];case 2:n=void 0,s.label=3;case 3:return i=n,a="evenodd"===T(this.element,t.styleSheets,"fill-rule"),e&&r||t.withinUse?a?t.pdf.fillStrokeEvenOdd(i):t.pdf.fillStroke(i):e?a?t.pdf.fillEvenOdd(i):t.pdf.fill(i):r?t.pdf.stroke():t.pdf.discardPath(),[2]}}))}))},e.prototype.getBoundingBoxCore=function(t){var e=this.getCachedPath(t);if(!e||!e.segments.length)return[0,0,0,0];for(var r=Number.POSITIVE_INFINITY,i=Number.POSITIVE_INFINITY,n=Number.NEGATIVE_INFINITY,a=Number.NEGATIVE_INFINITY,s=0,o=0,l=0;l<e.segments.length;l++){var u=e.segments[l];(u instanceof w||u instanceof k||u instanceof M)&&(s=u.x,o=u.y),u instanceof M?(r=Math.min(r,s,u.x1,u.x2,u.x),n=Math.max(n,s,u.x1,u.x2,u.x),i=Math.min(i,o,u.y1,u.y2,u.y),a=Math.max(a,o,u.y1,u.y2,u.y)):(r=Math.min(r,s),n=Math.max(n,s),i=Math.min(i,o),a=Math.max(a,o))}return[r,i,n-r,a-i]},e.prototype.getMarkers=function(t,e){var r=T(this.element,e.styleSheets,"marker-start"),i=T(this.element,e.styleSheets,"marker-mid"),n=T(this.element,e.styleSheets,"marker-end"),a=new B;if(r||i||n){n&&(n=ft(n)),r&&(r=ft(r)),i&&(i=ft(i));for(var s=t.segments,o=[1,0],l=void 0,u=!1,h=[1,0],f=!1,c=function(t){var e=s[t],c=r&&(1===t||!(s[t]instanceof w)&&s[t-1]instanceof w);c&&s.forEach((function(e,r){if(!f&&e instanceof C&&r>t){var i=s[r-1];f=(i instanceof w||i instanceof k||i instanceof M)&&i}}));var p=n&&(t===s.length-1||!(s[t]instanceof w)&&s[t+1]instanceof w),d=i&&t>0&&!(1===t&&s[t-1]instanceof w),g=s[t-1]||null;if(g instanceof w||g instanceof k||g instanceof M){if(e instanceof M)c&&a.addMarker(new N(r,[g.x,g.y],m(f?[f.x,f.y]:[g.x,g.y],[e.x1,e.y1]))),p&&a.addMarker(new N(n,[e.x,e.y],m([e.x2,e.y2],[e.x,e.y]))),d&&(l=y([g.x,g.y],[e.x1,e.y1]),l=g instanceof w?l:v(b(o,l)),a.addMarker(new N(i,[g.x,g.y],Math.atan2(l[1],l[0])))),o=y([e.x2,e.y2],[e.x,e.y]);else if(e instanceof w||e instanceof k){if(l=y([g.x,g.y],[e.x,e.y]),c){var x=f?y([f.x,f.y],[e.x,e.y]):l;a.addMarker(new N(r,[g.x,g.y],Math.atan2(x[1],x[0])))}if(p&&a.addMarker(new N(n,[e.x,e.y],Math.atan2(l[1],l[0]))),d){x=e instanceof w?o:g instanceof w?l:v(b(o,l));a.addMarker(new N(i,[g.x,g.y],Math.atan2(x[1],x[0])))}o=l}else if(e instanceof C){if(l=y([g.x,g.y],[u.x,u.y]),d){x=g instanceof w?l:v(b(o,l));a.addMarker(new N(i,[g.x,g.y],Math.atan2(x[1],x[0])))}if(p){x=v(b(l,h));a.addMarker(new N(n,[u.x,u.y],Math.atan2(x[1],x[0])))}o=l}}else{u=e instanceof w&&e;var S=s[t+1];(S instanceof w||S instanceof k||S instanceof M)&&(h=y([u.x,u.y],[S.x,S.y]))}},p=0;p<s.length;p++)c(p)}return a},e}(ut);function ft(t){var e=E.exec(t);return e&&e[1]||void 0}var ct=function(t){function e(e,r){return t.call(this,!0,e,r)||this}return s(e,t),e.prototype.getPath=function(t){if(t.withinClipPath||null===t.attributeState.stroke)return null;var e=parseFloat(this.element.getAttribute("x1")||"0"),r=parseFloat(this.element.getAttribute("y1")||"0"),i=parseFloat(this.element.getAttribute("x2")||"0"),n=parseFloat(this.element.getAttribute("y2")||"0");return e||i||r||n?(new S).moveTo(e,r).lineTo(i,n):null},e.prototype.computeNodeTransformCore=function(t){return t.pdf.unitMatrix},e.prototype.isVisible=function(t,e){return A(this,t,e)},e.prototype.fillOrStroke=function(e){return l(this,void 0,void 0,(function(){return u(this,(function(r){switch(r.label){case 0:return e.attributeState.fill=null,[4,t.prototype.fillOrStroke.call(this,e)];case 1:return r.sent(),[2]}}))}))},e}(ht),pt=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return s(e,t),e.prototype.apply=function(t){return l(this,void 0,void 0,(function(){var e,r,i,n,a;return u(this,(function(s){switch(s.label){case 0:return this.isVisible("hidden"!==t.attributeState.visibility,t)?((e=t.clone()).transform=e.pdf.unitMatrix,nt(e,this),r=T(this.element,e.styleSheets,"clip-path"),r&&"none"!==r&&(i=st(r,0,e))?i.isVisible(!0,e)?[4,ot(this,i,e)]:[3,2]:[3,3]):[2];case 1:return s.sent(),[3,3];case 2:return[2];case 3:at(e,t,this.element),n=0,a=this.children,s.label=4;case 4:return n<a.length?[4,a[n].render(e)]:[3,7];case 5:s.sent(),s.label=6;case 6:return n++,[3,4];case 7:return[2]}}))}))},e.prototype.getBoundingBoxCore=function(t){return U(t,this)},e.prototype.isVisible=function(t,e){return P(this,t,e)},e.prototype.computeNodeTransformCore=function(t){var e=parseFloat(T(this.element,t.styleSheets,"x")||"0"),r=parseFloat(T(this.element,t.styleSheets,"y")||"0"),i=this.element.getAttribute("viewBox");if(i){var n=I(i),a=parseFloat(T(this.element,t.styleSheets,"width")||T(this.element.ownerSVGElement,t.styleSheets,"width")||i[2]),s=parseFloat(T(this.element,t.styleSheets,"height")||T(this.element.ownerSVGElement,t.styleSheets,"height")||i[3]);return Y(this.element,n,e,r,a,s,t)}return t.pdf.Matrix(1,0,0,1,e,r)},e}($),dt=function(t,e){this.width=t,this.height=e},mt=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return s(e,t),e.prototype.renderCore=function(t){return l(this,void 0,void 0,(function(){var r,i,n,a,s,o,l,h,f,c,d,m,g;return u(this,(function(u){switch(u.label){case 0:return r=parseFloat,(i=this.element.getAttribute("href")||this.element.getAttribute("xlink:href"))?(n=i.substring(1),a=t.refsHandler.get(n),s=F(a.element,"symbol,svg")&&a.element.hasAttribute("viewBox"),o=r(T(this.element,t.styleSheets,"x")||"0"),l=r(T(this.element,t.styleSheets,"y")||"0"),h=void 0,f=void 0,s?(h=r(T(this.element,t.styleSheets,"width")||T(a.element,t.styleSheets,"width")||"0"),f=r(T(this.element,t.styleSheets,"height")||T(a.element,t.styleSheets,"height")||"0"),o+=r(T(a.element,t.styleSheets,"x")||"0"),l+=r(T(a.element,t.styleSheets,"y")||"0"),d=I(a.element.getAttribute("viewBox")),c=Y(a.element,d,o,l,h,f,t)):c=t.pdf.Matrix(1,0,0,1,o,l),m=new p(t.pdf,{refsHandler:t.refsHandler,styleSheets:t.styleSheets,withinUse:!0,viewport:s?new dt(h,f):t.viewport,svg2pdfParameters:t.svg2pdfParameters,textMeasure:t.textMeasure}),g=t.attributeState.color,[4,t.refsHandler.getRendered(n,g,(function(t){return e.renderReferencedNode(t,n,g,m)}))]):[2];case 1:return u.sent(),t.pdf.saveGraphicsState(),t.pdf.setCurrentTransformationMatrix(t.transform),s&&"visible"!==T(a.element,t.styleSheets,"overflow")&&(t.pdf.rect(o,l,h,f),t.pdf.clip().discardPath()),t.pdf.doFormObject(t.refsHandler.generateKey(n,g),c),t.pdf.restoreGraphicsState(),[2]}}))}))},e.renderReferencedNode=function(t,e,r,i){return l(this,void 0,void 0,(function(){var n;return u(this,(function(a){switch(a.label){case 0:return n=[(n=t.getBoundingBox(i))[0]-.5*n[2],n[1]-.5*n[3],2*n[2],2*n[3]],i.attributeState.color=r,i.pdf.beginFormObject(n[0],n[1],n[2],n[3],i.pdf.unitMatrix),t instanceof pt?[4,t.apply(i)]:[3,2];case 1:return a.sent(),[3,4];case 2:return[4,t.render(i)];case 3:a.sent(),a.label=4;case 4:return i.pdf.endFormObject(i.refsHandler.generateKey(e,r)),[2]}}))}))},e.prototype.getBoundingBoxCore=function(t){return z(this.element,t)},e.prototype.isVisible=function(t,e){return A(this,t,e)},e.prototype.computeNodeTransformCore=function(t){return t.pdf.unitMatrix},e}(ut),gt=function(t){function e(e,r){return t.call(this,!1,e,r)||this}return s(e,t),e.prototype.getPath=function(t){var e=parseFloat(T(this.element,t.styleSheets,"width")||"0"),r=parseFloat(T(this.element,t.styleSheets,"height")||"0");if(!isFinite(e)||e<=0||!isFinite(r)||r<=0)return null;var i=T(this.element,t.styleSheets,"rx"),n=T(this.element,t.styleSheets,"ry"),a=Math.min(parseFloat(i||n||"0"),.5*e),s=Math.min(parseFloat(n||i||"0"),.5*r),o=parseFloat(T(this.element,t.styleSheets,"x")||"0"),l=parseFloat(T(this.element,t.styleSheets,"y")||"0"),u=4/3*(Math.SQRT2-1);return 0===a&&0===s?(new S).moveTo(o,l).lineTo(o+e,l).lineTo(o+e,l+r).lineTo(o,l+r).close():(new S).moveTo(o+=a,l).lineTo(o+=e-2*a,l).curveTo(o+a*u,l,o+a,l+(s-s*u),o+=a,l+=s).lineTo(o,l+=r-2*s).curveTo(o,l+s*u,o-a*u,l+s,o-=a,l+=s).lineTo(o+=2*a-e,l).curveTo(o-a*u,l,o-a,l-s*u,o-=a,l-=s).lineTo(o,l+=2*s-r).curveTo(o,l-s*u,o+a*u,l-s,o+=a,l-=s).close()},e.prototype.computeNodeTransformCore=function(t){return t.pdf.unitMatrix},e.prototype.isVisible=function(t,e){return A(this,t,e)},e}(ht),vt=function(t){function e(e,r){return t.call(this,!1,e,r)||this}return s(e,t),e.prototype.getPath=function(t){var e=this.getRx(t),r=this.getRy(t);if(!isFinite(e)||r<=0||!isFinite(r)||r<=0)return null;var i=parseFloat(T(this.element,t.styleSheets,"cx")||"0"),n=parseFloat(T(this.element,t.styleSheets,"cy")||"0"),a=4/3*(Math.SQRT2-1)*e,s=4/3*(Math.SQRT2-1)*r;return(new S).moveTo(i+e,n).curveTo(i+e,n-s,i+a,n-r,i,n-r).curveTo(i-a,n-r,i-e,n-s,i-e,n).curveTo(i-e,n+s,i-a,n+r,i,n+r).curveTo(i+a,n+r,i+e,n+s,i+e,n)},e.prototype.computeNodeTransformCore=function(t){return t.pdf.unitMatrix},e.prototype.isVisible=function(t,e){return A(this,t,e)},e}(ht),yt=function(t){function e(e,r){return t.call(this,e,r)||this}return s(e,t),e.prototype.getRx=function(t){return parseFloat(T(this.element,t.styleSheets,"rx")||"0")},e.prototype.getRy=function(t){return parseFloat(T(this.element,t.styleSheets,"ry")||"0")},e}(vt);function bt(t){var e="invisible",r=t.stroke&&0!==t.strokeWidth,i=t.fill;return i&&r?e="fillThenStroke":i?e="fill":r&&(e="stroke"),e}function xt(t){return t.replace(/[\n\r]/g,"")}function St(t){return t.replace(/[\t]/g," ")}function wt(t){return t.replace(/ +/g," ")}function kt(t,e,r){switch(T(t,r.styleSheets,"text-transform")){case"uppercase":return e.toUpperCase();case"lowercase":return e.toLowerCase();default:return e}}var Mt=function(){function t(t,e,r,i){this.textNode=t,this.texts=[],this.textNodes=[],this.contexts=[],this.textAnchor=e,this.originX=r,this.originY=i,this.textMeasures=[]}return t.prototype.setX=function(t){this.originX=t},t.prototype.setY=function(t){this.originY=t},t.prototype.add=function(t,e,r){this.texts.push(e),this.textNodes.push(t),this.contexts.push(r)},t.prototype.rightTrimText=function(){for(var t=this.texts.length-1;t>=0;t--)if("default"===this.contexts[t].attributeState.xmlSpace&&(this.texts[t]=this.texts[t].replace(/\s+$/,"")),this.texts[t].match(/[^\s]/))return!1;return!0},t.prototype.measureText=function(t){for(var e=0;e<this.texts.length;e++)this.textMeasures.push({width:t.textMeasure.measureTextWidth(this.texts[e],this.contexts[e].attributeState),length:this.texts[e].length})},t.prototype.put=function(e,r){var i,n,a,s,o=[],l=[],u=[],h=this.originX,f=this.originY,c=h,p=h;for(i=0;i<this.textNodes.length;i++){n=this.textNodes[i],a=this.contexts[i],s=this.textMeasures[i]||{width:e.textMeasure.measureTextWidth(this.texts[i],this.contexts[i].attributeState),length:this.texts[i].length};var d=h,m=f;if("#text"!==n.nodeName&&!o.includes(n)){o.push(n);var g=t.resolveRelativePositionAttribute(n,"dx");null!==g&&(d+=O(g,a.attributeState.fontSize));var v=t.resolveRelativePositionAttribute(n,"dy");null!==v&&(m+=O(v,a.attributeState.fontSize))}l[i]=d,u[i]=m,h=d+s.width+s.length*r,f=m,c=Math.min(c,d),p=Math.max(p,h)}var y=0;switch(this.textAnchor){case"start":y=0;break;case"middle":y=(p-c)/2;break;case"end":y=p-c}for(i=0;i<this.textNodes.length;i++)if(n=this.textNodes[i],a=this.contexts[i],"#text"===n.nodeName||"hidden"!==a.attributeState.visibility){e.pdf.saveGraphicsState(),at(a,e,n);var b=a.attributeState.alignmentBaseline,x=bt(a.attributeState);e.pdf.text(this.texts[i],l[i]-y,u[i],{baseline:_(b),angle:e.transform,renderingMode:"fill"===x?void 0:x,charSpace:0===r?void 0:r}),e.pdf.restoreGraphicsState()}return[h,f]},t.resolveRelativePositionAttribute=function(t,e){for(var r,i=t;i&&F(i,"tspan");){if(i.hasAttribute(e))return i.getAttribute(e);if((null===(r=t.parentElement)||void 0===r?void 0:r.firstChild)!==t)break;i=i.parentElement}return null},t}(),Ct=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return s(e,t),e.prototype.processTSpans=function(t,e,r,i,n,a){for(var s=r.pdf.getFontSize(),o=r.attributeState.xmlSpace,l=!0,u=!1,h=0;h<e.childNodes.length;h++){var f=e.childNodes[h];if(f.textContent){var c=f.textContent;if("#text"===f.nodeName){var p=xt(c);p=St(p),"default"===o&&(p=wt(p),l&&p.match(/^\s/)&&(u=!0),p.match(/[^\s]/)&&(l=!1),a.prevText.match(/\s$/)&&(p=p.replace(/^\s+/,"")));var d=kt(e,p,r);n.add(e,d,r),a.prevText=c,a.prevContext=r}else if(F(f,"title"));else if(F(f,"tspan")){var m=f,g=m.getAttribute("x");if(null!==g){var v=O(g,s);n=new Mt(this,T(m,r.styleSheets,"text-anchor")||r.attributeState.textAnchor,v,0),i.push({type:"y",chunk:n})}var y=m.getAttribute("y");if(null!==y){var b=O(y,s);n=new Mt(this,T(m,r.styleSheets,"text-anchor")||r.attributeState.textAnchor,0,b),i.push({type:"x",chunk:n})}var x=r.clone();nt(x,t,m),this.processTSpans(t,m,x,i,n,a)}}}return u},e.prototype.renderCore=function(t){return l(this,void 0,void 0,(function(){var e,r,i,n,a,s,o,l,h,f,c,p,d,m,g,v,y,b,x,S,w,k,M;return u(this,(function(u){if(t.pdf.saveGraphicsState(),e=0,r=0,i=1,n=t.pdf.getFontSize(),a=O(this.element.getAttribute("x"),n),s=O(this.element.getAttribute("y"),n),o=O(this.element.getAttribute("dx"),n),l=O(this.element.getAttribute("dy"),n),h=parseFloat(this.element.getAttribute("textLength")||"0"),f=t.attributeState.visibility,0===this.element.childElementCount)c=this.element.textContent||"",p=function(t,e){return t=St(t=xt(t)),"default"===e.xmlSpace&&(t=wt(t=t.trim())),t}(c,t.attributeState),d=kt(this.element,p,t),e=t.textMeasure.getTextOffset(d,t.attributeState),h>0&&(m=t.textMeasure.measureTextWidth(d,t.attributeState),"default"===t.attributeState.xmlSpace&&c.match(/^\s/)&&(i=0),r=(h-m)/(d.length-i)||0),"visible"===f&&(g=t.attributeState.alignmentBaseline,v=bt(t.attributeState),t.pdf.text(d,a+o-e,s+l,{baseline:_(g),angle:t.transform,renderingMode:"fill"===v?void 0:v,charSpace:0===r?void 0:r}));else{for(y=[],b=new Mt(this,t.attributeState.textAnchor,a+o,s+l),y.push({type:"",chunk:b}),x=this.processTSpans(this,this.element,t,y,b,{prevText:" ",prevContext:t}),i=x?0:1,S=!0,w=y.length-1;w>=0;w--)S&&(S=y[w].chunk.rightTrimText());h>0&&(k=0,M=0,y.forEach((function(e){var r=e.chunk;r.measureText(t),r.textMeasures.forEach((function(t){var e=t.width,r=t.length;k+=e,M+=r}))})),r=(h-k)/(M-i)),y.reduce((function(e,i){var n=i.type,a=i.chunk;return"x"===n?a.setX(e[0]):"y"===n&&a.setY(e[1]),a.put(t,r)}),[0,0])}return t.pdf.restoreGraphicsState(),[2]}))}))},e.prototype.isVisible=function(t,e){return P(this,t,e)},e.prototype.getBoundingBoxCore=function(t){return z(this.element,t)},e.prototype.computeNodeTransformCore=function(t){return t.pdf.unitMatrix},e}(ut),Ft={a:7,c:6,h:1,l:2,m:2,r:4,q:4,s:4,t:2,v:1,z:0},Tt=[5760,6158,8192,8193,8194,8195,8196,8197,8198,8199,8200,8201,8202,8239,8287,12288,65279];function At(t){return t>=48&&t<=57}function Pt(t){return t>=48&&t<=57||43===t||45===t||46===t}function Bt(t){this.index=0,this.path=t,this.max=t.length,this.result=[],this.param=0,this.err="",this.segmentStart=0,this.data=[]}function Nt(t){for(;t.index<t.max&&(10===(e=t.path.charCodeAt(t.index))||13===e||8232===e||8233===e||32===e||9===e||11===e||12===e||160===e||e>=5760&&Tt.indexOf(e)>=0);)t.index++;var e}function Et(t){var e=t.path.charCodeAt(t.index);return 48===e?(t.param=0,void t.index++):49===e?(t.param=1,void t.index++):void(t.err="SvgPath: arc flag can be 0 or 1 only (at pos "+t.index+")")}function Lt(t){var e,r=t.index,i=r,n=t.max,a=!1,s=!1,o=!1,l=!1;if(i>=n)t.err="SvgPath: missed param (at pos "+i+")";else if(43!==(e=t.path.charCodeAt(i))&&45!==e||(e=++i<n?t.path.charCodeAt(i):0),At(e)||46===e){if(46!==e){if(a=48===e,e=++i<n?t.path.charCodeAt(i):0,a&&i<n&&e&&At(e))return void(t.err="SvgPath: numbers started with `0` such as `09` are illegal (at pos "+r+")");for(;i<n&&At(t.path.charCodeAt(i));)i++,s=!0;e=i<n?t.path.charCodeAt(i):0}if(46===e){for(l=!0,i++;At(t.path.charCodeAt(i));)i++,o=!0;e=i<n?t.path.charCodeAt(i):0}if(101===e||69===e){if(l&&!s&&!o)return void(t.err="SvgPath: invalid float exponent (at pos "+i+")");if(43!==(e=++i<n?t.path.charCodeAt(i):0)&&45!==e||i++,!(i<n&&At(t.path.charCodeAt(i))))return void(t.err="SvgPath: invalid float exponent (at pos "+i+")");for(;i<n&&At(t.path.charCodeAt(i));)i++}t.index=i,t.param=parseFloat(t.path.slice(r,i))+0}else t.err="SvgPath: param should start with 0..9 or `.` (at pos "+i+")"}function Ot(t){var e,r;r=(e=t.path[t.segmentStart]).toLowerCase();var i=t.data;if("m"===r&&i.length>2&&(t.result.push([e,i[0],i[1]]),i=i.slice(2),r="l",e="m"===e?"l":"L"),"r"===r)t.result.push([e].concat(i));else for(;i.length>=Ft[r]&&(t.result.push([e].concat(i.splice(0,Ft[r]))),Ft[r]););}function _t(t){var e,r,i,n,a,s=t.max;if(t.segmentStart=t.index,e=t.path.charCodeAt(t.index),r=97==(32|e),function(t){switch(32|t){case 109:case 122:case 108:case 104:case 118:case 99:case 115:case 113:case 116:case 97:case 114:return!0}return!1}(e))if(n=Ft[t.path[t.index].toLowerCase()],t.index++,Nt(t),t.data=[],n){for(i=!1;;){for(a=n;a>0;a--){if(!r||3!==a&&4!==a?Lt(t):Et(t),t.err.length)return;t.data.push(t.param),Nt(t),i=!1,t.index<s&&44===t.path.charCodeAt(t.index)&&(t.index++,Nt(t),i=!0)}if(!i){if(t.index>=t.max)break;if(!Pt(t.path.charCodeAt(t.index)))break}}Ot(t)}else Ot(t);else t.err="SvgPath: bad command "+t.path[t.index]+" (at pos "+t.index+")"}function It(){if(!(this instanceof It))return new It;this.queue=[],this.cache=null}It.prototype.matrix=function(t){return 1===t[0]&&0===t[1]&&0===t[2]&&1===t[3]&&0===t[4]&&0===t[5]||(this.cache=null,this.queue.push(t)),this},It.prototype.translate=function(t,e){return 0===t&&0===e||(this.cache=null,this.queue.push([1,0,0,1,t,e])),this},It.prototype.scale=function(t,e){return 1===t&&1===e||(this.cache=null,this.queue.push([t,0,0,e,0,0])),this},It.prototype.rotate=function(t,e,r){var i,n,a;return 0!==t&&(this.translate(e,r),i=t*Math.PI/180,n=Math.cos(i),a=Math.sin(i),this.queue.push([n,a,-a,n,0,0]),this.cache=null,this.translate(-e,-r)),this},It.prototype.skewX=function(t){return 0!==t&&(this.cache=null,this.queue.push([1,0,Math.tan(t*Math.PI/180),1,0,0])),this},It.prototype.skewY=function(t){return 0!==t&&(this.cache=null,this.queue.push([1,Math.tan(t*Math.PI/180),0,1,0,0])),this},It.prototype.toArray=function(){if(this.cache)return this.cache;if(!this.queue.length)return this.cache=[1,0,0,1,0,0],this.cache;if(this.cache=this.queue[0],1===this.queue.length)return this.cache;for(var t=1;t<this.queue.length;t++)this.cache=(e=this.cache,r=this.queue[t],[e[0]*r[0]+e[2]*r[1],e[1]*r[0]+e[3]*r[1],e[0]*r[2]+e[2]*r[3],e[1]*r[2]+e[3]*r[3],e[0]*r[4]+e[2]*r[5]+e[4],e[1]*r[4]+e[3]*r[5]+e[5]]);var e,r;return this.cache},It.prototype.calc=function(t,e,r){var i;return this.queue.length?(this.cache||(this.cache=this.toArray()),[t*(i=this.cache)[0]+e*i[2]+(r?0:i[4]),t*i[1]+e*i[3]+(r?0:i[5])]):[t,e]};var Ht=It,Dt={matrix:!0,scale:!0,rotate:!0,translate:!0,skewX:!0,skewY:!0},Vt=/\s*(matrix|translate|scale|rotate|skewX|skewY)\s*\(\s*(.+?)\s*\)[\s,]*/,Rt=/[\s,]+/,Wt=2*Math.PI;function qt(t,e,r,i){var n=t*r+e*i;return n>1&&(n=1),n<-1&&(n=-1),(t*i-e*r<0?-1:1)*Math.acos(n)}function jt(t,e){var r=4/3*Math.tan(e/4),i=Math.cos(t),n=Math.sin(t),a=Math.cos(t+e),s=Math.sin(t+e);return[i,n,i-n*r,n+i*r,a+s*r,s-a*r,a,s]}var Gt=function(t,e,r,i,n,a,s,o,l){var u=Math.sin(l*Wt/360),h=Math.cos(l*Wt/360),f=h*(t-r)/2+u*(e-i)/2,c=-u*(t-r)/2+h*(e-i)/2;if(0===f&&0===c)return[];if(0===s||0===o)return[];s=Math.abs(s),o=Math.abs(o);var p=f*f/(s*s)+c*c/(o*o);p>1&&(s*=Math.sqrt(p),o*=Math.sqrt(p));var d=function(t,e,r,i,n,a,s,o,l,u){var h=u*(t-r)/2+l*(e-i)/2,f=-l*(t-r)/2+u*(e-i)/2,c=s*s,p=o*o,d=h*h,m=f*f,g=c*p-c*m-p*d;g<0&&(g=0),g/=c*m+p*d;var v=(g=Math.sqrt(g)*(n===a?-1:1))*s/o*f,y=g*-o/s*h,b=u*v-l*y+(t+r)/2,x=l*v+u*y+(e+i)/2,S=(h-v)/s,w=(f-y)/o,k=(-h-v)/s,M=(-f-y)/o,C=qt(1,0,S,w),F=qt(S,w,k,M);return 0===a&&F>0&&(F-=Wt),1===a&&F<0&&(F+=Wt),[b,x,C,F]}(t,e,r,i,n,a,s,o,u,h),m=[],g=d[2],v=d[3],y=Math.max(Math.ceil(Math.abs(v)/(Wt/4)),1);v/=y;for(var b=0;b<y;b++)m.push(jt(g,v)),g+=v;return m.map((function(t){for(var e=0;e<t.length;e+=2){var r=t[e+0],i=t[e+1],n=h*(r*=s)-u*(i*=o),a=u*r+h*i;t[e+0]=n+d[0],t[e+1]=a+d[1]}return t}))},Ut=Math.PI/180;function zt(t,e,r){if(!(this instanceof zt))return new zt(t,e,r);this.rx=t,this.ry=e,this.ax=r}zt.prototype.transform=function(t){var e=Math.cos(this.ax*Ut),r=Math.sin(this.ax*Ut),i=[this.rx*(t[0]*e+t[2]*r),this.rx*(t[1]*e+t[3]*r),this.ry*(-t[0]*r+t[2]*e),this.ry*(-t[1]*r+t[3]*e)],n=i[0]*i[0]+i[2]*i[2],a=i[1]*i[1]+i[3]*i[3],s=((i[0]-i[3])*(i[0]-i[3])+(i[2]+i[1])*(i[2]+i[1]))*((i[0]+i[3])*(i[0]+i[3])+(i[2]-i[1])*(i[2]-i[1])),o=(n+a)/2;if(s<1e-10*o)return this.rx=this.ry=Math.sqrt(o),this.ax=0,this;var l=i[0]*i[1]+i[2]*i[3],u=o+(s=Math.sqrt(s))/2,h=o-s/2;return this.ax=Math.abs(l)<1e-10&&Math.abs(u-a)<1e-10?90:180*Math.atan(Math.abs(l)>Math.abs(u-a)?(u-n)/l:l/(u-a))/Math.PI,this.ax>=0?(this.rx=Math.sqrt(u),this.ry=Math.sqrt(h)):(this.ax+=90,this.rx=Math.sqrt(h),this.ry=Math.sqrt(u)),this},zt.prototype.isDegenerate=function(){return this.rx<1e-10*this.ry||this.ry<1e-10*this.rx};var Yt=zt;function Xt(t){if(!(this instanceof Xt))return new Xt(t);var e=function(t){var e=new Bt(t),r=e.max;for(Nt(e);e.index<r&&!e.err.length;)_t(e);return e.err.length?e.result=[]:e.result.length&&("mM".indexOf(e.result[0][0])<0?(e.err="SvgPath: string should start with `M` or `m`",e.result=[]):e.result[0][0]="M"),{err:e.err,segments:e.result}}(t);this.segments=e.segments,this.err=e.err,this.__stack=[]}Xt.from=function(t){if("string"==typeof t)return new Xt(t);if(t instanceof Xt){var e=new Xt("");return e.err=t.err,e.segments=t.segments.map((function(t){return t.slice()})),e.__stack=t.__stack.map((function(t){return Ht().matrix(t.toArray())})),e}throw new Error("SvgPath.from: invalid param type "+t)},Xt.prototype.__matrix=function(t){var e,r=this;t.queue.length&&this.iterate((function(i,n,a,s){var o,l,u,h;switch(i[0]){case"v":l=0===(o=t.calc(0,i[1],!0))[0]?["v",o[1]]:["l",o[0],o[1]];break;case"V":l=(o=t.calc(a,i[1],!1))[0]===t.calc(a,s,!1)[0]?["V",o[1]]:["L",o[0],o[1]];break;case"h":l=0===(o=t.calc(i[1],0,!0))[1]?["h",o[0]]:["l",o[0],o[1]];break;case"H":l=(o=t.calc(i[1],s,!1))[1]===t.calc(a,s,!1)[1]?["H",o[0]]:["L",o[0],o[1]];break;case"a":case"A":var f=t.toArray(),c=Yt(i[1],i[2],i[3]).transform(f);if(f[0]*f[3]-f[1]*f[2]<0&&(i[5]=i[5]?"0":"1"),o=t.calc(i[6],i[7],"a"===i[0]),"A"===i[0]&&i[6]===a&&i[7]===s||"a"===i[0]&&0===i[6]&&0===i[7]){l=["a"===i[0]?"l":"L",o[0],o[1]];break}l=c.isDegenerate()?["a"===i[0]?"l":"L",o[0],o[1]]:[i[0],c.rx,c.ry,c.ax,i[4],i[5],o[0],o[1]];break;case"m":h=n>0,l=["m",(o=t.calc(i[1],i[2],h))[0],o[1]];break;default:for(l=[u=i[0]],h=u.toLowerCase()===u,e=1;e<i.length;e+=2)o=t.calc(i[e],i[e+1],h),l.push(o[0],o[1])}r.segments[n]=l}),!0)},Xt.prototype.__evaluateStack=function(){var t,e;if(this.__stack.length){if(1===this.__stack.length)return this.__matrix(this.__stack[0]),void(this.__stack=[]);for(t=Ht(),e=this.__stack.length;--e>=0;)t.matrix(this.__stack[e].toArray());this.__matrix(t),this.__stack=[]}},Xt.prototype.toString=function(){var t="",e="",r=!1;this.__evaluateStack();for(var i=0,n=this.segments.length;i<n;i++){var a=this.segments[i],s=a[0];s!==e||"m"===s||"M"===s?("m"===s&&"z"===e&&(t+=" "),t+=s,r=!1):r=!0;for(var o=1;o<a.length;o++){var l=a[o];1===o?r&&l>=0&&(t+=" "):l>=0&&(t+=" "),t+=l}e=s}return t},Xt.prototype.translate=function(t,e){return this.__stack.push(Ht().translate(t,e||0)),this},Xt.prototype.scale=function(t,e){return this.__stack.push(Ht().scale(t,e||0===e?e:t)),this},Xt.prototype.rotate=function(t,e,r){return this.__stack.push(Ht().rotate(t,e||0,r||0)),this},Xt.prototype.skewX=function(t){return this.__stack.push(Ht().skewX(t)),this},Xt.prototype.skewY=function(t){return this.__stack.push(Ht().skewY(t)),this},Xt.prototype.matrix=function(t){return this.__stack.push(Ht().matrix(t)),this},Xt.prototype.transform=function(t){return t.trim()?(this.__stack.push(function(t){var e,r,i=new Ht;return t.split(Vt).forEach((function(t){if(t.length)if(void 0===Dt[t])switch(r=t.split(Rt).map((function(t){return+t||0})),e){case"matrix":return void(6===r.length&&i.matrix(r));case"scale":return void(1===r.length?i.scale(r[0],r[0]):2===r.length&&i.scale(r[0],r[1]));case"rotate":return void(1===r.length?i.rotate(r[0],0,0):3===r.length&&i.rotate(r[0],r[1],r[2]));case"translate":return void(1===r.length?i.translate(r[0],0):2===r.length&&i.translate(r[0],r[1]));case"skewX":return void(1===r.length&&i.skewX(r[0]));case"skewY":return void(1===r.length&&i.skewY(r[0]))}else e=t})),i}(t)),this):this},Xt.prototype.round=function(t){var e,r=0,i=0,n=0,a=0;return t=t||0,this.__evaluateStack(),this.segments.forEach((function(s){var o=s[0].toLowerCase()===s[0];switch(s[0]){case"H":case"h":return o&&(s[1]+=n),n=s[1]-s[1].toFixed(t),void(s[1]=+s[1].toFixed(t));case"V":case"v":return o&&(s[1]+=a),a=s[1]-s[1].toFixed(t),void(s[1]=+s[1].toFixed(t));case"Z":case"z":return n=r,void(a=i);case"M":case"m":return o&&(s[1]+=n,s[2]+=a),n=s[1]-s[1].toFixed(t),a=s[2]-s[2].toFixed(t),r=n,i=a,s[1]=+s[1].toFixed(t),void(s[2]=+s[2].toFixed(t));case"A":case"a":return o&&(s[6]+=n,s[7]+=a),n=s[6]-s[6].toFixed(t),a=s[7]-s[7].toFixed(t),s[1]=+s[1].toFixed(t),s[2]=+s[2].toFixed(t),s[3]=+s[3].toFixed(t+2),s[6]=+s[6].toFixed(t),void(s[7]=+s[7].toFixed(t));default:return e=s.length,o&&(s[e-2]+=n,s[e-1]+=a),n=s[e-2]-s[e-2].toFixed(t),a=s[e-1]-s[e-1].toFixed(t),void s.forEach((function(e,r){r&&(s[r]=+s[r].toFixed(t))}))}})),this},Xt.prototype.iterate=function(t,e){var r,i,n,a=this.segments,s={},o=!1,l=0,u=0,h=0,f=0;if(e||this.__evaluateStack(),a.forEach((function(e,r){var i=t(e,r,l,u);Array.isArray(i)&&(s[r]=i,o=!0);var n=e[0]===e[0].toLowerCase();switch(e[0]){case"m":case"M":return l=e[1]+(n?l:0),u=e[2]+(n?u:0),h=l,void(f=u);case"h":case"H":return void(l=e[1]+(n?l:0));case"v":case"V":return void(u=e[1]+(n?u:0));case"z":case"Z":return l=h,void(u=f);default:l=e[e.length-2]+(n?l:0),u=e[e.length-1]+(n?u:0)}})),!o)return this;for(n=[],r=0;r<a.length;r++)if(void 0!==s[r])for(i=0;i<s[r].length;i++)n.push(s[r][i]);else n.push(a[r]);return this.segments=n,this},Xt.prototype.abs=function(){return this.iterate((function(t,e,r,i){var n,a=t[0],s=a.toUpperCase();if(a!==s)switch(t[0]=s,a){case"v":return void(t[1]+=i);case"a":return t[6]+=r,void(t[7]+=i);default:for(n=1;n<t.length;n++)t[n]+=n%2?r:i}}),!0),this},Xt.prototype.rel=function(){return this.iterate((function(t,e,r,i){var n,a=t[0],s=a.toLowerCase();if(a!==s&&(0!==e||"M"!==a))switch(t[0]=s,a){case"V":return void(t[1]-=i);case"A":return t[6]-=r,void(t[7]-=i);default:for(n=1;n<t.length;n++)t[n]-=n%2?r:i}}),!0),this},Xt.prototype.unarc=function(){return this.iterate((function(t,e,r,i){var n,a,s,o=[],l=t[0];return"A"!==l&&"a"!==l?null:("a"===l?(a=r+t[6],s=i+t[7]):(a=t[6],s=t[7]),0===(n=Gt(r,i,a,s,t[4],t[5],t[1],t[2],t[3])).length?[["a"===t[0]?"l":"L",t[6],t[7]]]:(n.forEach((function(t){o.push(["C",t[2],t[3],t[4],t[5],t[6],t[7]])})),o))})),this},Xt.prototype.unshort=function(){var t,e,r,i,n,a=this.segments;return this.iterate((function(s,o,l,u){var h,f=s[0],c=f.toUpperCase();o&&("T"===c?(h="t"===f,"Q"===(r=a[o-1])[0]?(t=r[1]-l,e=r[2]-u):"q"===r[0]?(t=r[1]-r[3],e=r[2]-r[4]):(t=0,e=0),i=-t,n=-e,h||(i+=l,n+=u),a[o]=[h?"q":"Q",i,n,s[1],s[2]]):"S"===c&&(h="s"===f,"C"===(r=a[o-1])[0]?(t=r[3]-l,e=r[4]-u):"c"===r[0]?(t=r[3]-r[5],e=r[4]-r[6]):(t=0,e=0),i=-t,n=-e,h||(i+=l,n+=u),a[o]=[h?"c":"C",i,n,s[1],s[2],s[3],s[4]]))})),this};var Qt=Xt,$t=function(t){function e(e,r){return t.call(this,!0,e,r)||this}return s(e,t),e.prototype.computeNodeTransformCore=function(t){return t.pdf.unitMatrix},e.prototype.isVisible=function(t,e){return A(this,t,e)},e.prototype.getPath=function(t){var e,r,i=new Qt(T(this.element,t.styleSheets,"d")||"").unshort().unarc().abs(),n=new S;return i.iterate((function(t){switch(t[0]){case"M":n.moveTo(t[1],t[2]);break;case"L":n.lineTo(t[1],t[2]);break;case"H":n.lineTo(t[1],r);break;case"V":n.lineTo(e,t[1]);break;case"C":n.curveTo(t[1],t[2],t[3],t[4],t[5],t[6]);break;case"Q":var i=g([e,r],[t[1],t[2]]),a=g([t[3],t[4]],[t[1],t[2]]);n.curveTo(i[0],i[1],a[0],a[1],t[3],t[4]);break;case"Z":n.close()}switch(t[0]){case"M":case"L":e=t[1],r=t[2];break;case"H":e=t[1];break;case"V":r=t[1];break;case"C":e=t[5],r=t[6];break;case"Q":e=t[3],r=t[4]}})),n},e}(ht),Kt=/^\s*data:(([^/,;]+\/[^/,;]+)(?:;([^,;=]+=[^,;=]+))?)?(?:;(base64))?,((?:.|\s)*)$/i,Zt=function(t){function e(r,i){var n=t.call(this,r,i)||this;return n.imageLoadingPromise=null,n.imageUrl=n.element.getAttribute("xlink:href")||n.element.getAttribute("href"),n.imageUrl&&(n.imageLoadingPromise=e.fetchImageData(n.imageUrl)),n}return s(e,t),e.prototype.renderCore=function(t){return l(this,void 0,void 0,(function(){var e,r,i,n,a,s,o,l,h,f,c,m;return u(this,(function(u){switch(u.label){case 0:return this.imageLoadingPromise?(t.pdf.setCurrentTransformationMatrix(t.transform),e=parseFloat(T(this.element,t.styleSheets,"width")||"0"),r=parseFloat(T(this.element,t.styleSheets,"height")||"0"),i=parseFloat(T(this.element,t.styleSheets,"x")||"0"),n=parseFloat(T(this.element,t.styleSheets,"y")||"0"),!isFinite(e)||e<=0||!isFinite(r)||r<=0?[2]:[4,this.imageLoadingPromise]):[2];case 1:return a=u.sent(),s=a.data,0!==(o=a.format).indexOf("svg")?[3,3]:(l=new DOMParser,h=l.parseFromString(s,"image/svg+xml").firstElementChild,(!(f=this.element.getAttribute("preserveAspectRatio"))||f.indexOf("defer")<0||!h.getAttribute("preserveAspectRatio"))&&h.setAttribute("preserveAspectRatio",f||""),h.setAttribute("x",String(i)),h.setAttribute("y",String(n)),h.setAttribute("width",String(e)),h.setAttribute("height",String(r)),[4,ue(h,c={}).render(new p(t.pdf,{refsHandler:new d(c),styleSheets:t.styleSheets,viewport:new dt(e,r),svg2pdfParameters:t.svg2pdfParameters,textMeasure:t.textMeasure}))]);case 2:return u.sent(),[2];case 3:m="data:image/"+o+";base64,"+btoa(s);try{t.pdf.addImage(m,"",i,n,e,r)}catch(t){"object"==typeof console&&console.warn&&console.warn("Could not load image "+this.imageUrl+". \n"+t)}u.label=4;case 4:return[2]}}))}))},e.prototype.getBoundingBoxCore=function(t){return z(this.element,t)},e.prototype.computeNodeTransformCore=function(t){return t.pdf.unitMatrix},e.prototype.isVisible=function(t,e){return A(this,t,e)},e.fetchImageData=function(t){return l(this,void 0,void 0,(function(){var r,i,n,a,s;return u(this,(function(o){switch(o.label){case 0:if(!(n=t.match(Kt)))return[3,1];if(a=n[2],"image"!==(s=a.split("/"))[0])throw new Error("Unsupported image URL: "+t);return i=s[1],r=n[5],"base64"===n[4]?(r=r.replace(/\s/g,""),r=atob(r)):r=decodeURIComponent(r),[3,3];case 1:return[4,e.fetchImage(t)];case 2:r=o.sent(),i=t.substring(t.lastIndexOf(".")+1),o.label=3;case 3:return[2,{data:r,format:i}]}}))}))},e.fetchImage=function(t){return new Promise((function(e,r){var i=new XMLHttpRequest;i.open("GET",t,!0),i.responseType="arraybuffer",i.onload=function(){if(200!==i.status)throw new Error("Error "+i.status+": Failed to load image '"+t+"'");for(var r=new Uint8Array(i.response),n="",a=0;a<r.length;a++)n+=String.fromCharCode(r[a]);e(n)},i.onerror=r,i.onabort=r,i.send(null)}))},e.getMimeType=function(t){switch(t=t.toLowerCase()){case"jpg":case"jpeg":return"image/jpeg";default:return"image/"+t}},e}(ut),Jt=function(t){function e(e,r,i){var n=t.call(this,!0,r,i)||this;return n.closed=e,n}return s(e,t),e.prototype.getPath=function(t){if(!this.element.hasAttribute("points")||""===this.element.getAttribute("points"))return null;var r=e.parsePointsString(this.element.getAttribute("points")),i=new S;if(r.length<1)return i;i.moveTo(r[0][0],r[0][1]);for(var n=1;n<r.length;n++)i.lineTo(r[n][0],r[n][1]);return this.closed&&i.close(),i},e.prototype.isVisible=function(t,e){return A(this,t,e)},e.prototype.computeNodeTransformCore=function(t){return t.pdf.unitMatrix},e.parsePointsString=function(t){for(var e=I(t),r=[],i=0;i<e.length-1;i+=2){var n=e[i],a=e[i+1];r.push([n,a])}return r},e}(ht),te=function(t){function e(e,r){return t.call(this,!0,e,r)||this}return s(e,t),e}(Jt),ee=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return s(e,t),e.prototype.render=function(t){return Promise.resolve()},e.prototype.getBoundingBoxCore=function(t){return[0,0,0,0]},e.prototype.computeNodeTransformCore=function(t){return t.pdf.unitMatrix},e.prototype.isVisible=function(t,e){return A(this,t,e)},e}(Q),re=function(t){function r(){return null!==t&&t.apply(this,arguments)||this}return s(r,t),r.prototype.apply=function(t){return l(this,void 0,void 0,(function(){var r,i,n,a,s;return u(this,(function(o){switch(o.label){case 0:r=this.computeNodeTransform(t),i=this.getBoundingBox(t),t.pdf.beginFormObject(i[0],i[1],i[2],i[3],r),function(t){var r=t.attributeState,i=t.pdf,n=1,a=1;n*=r.fillOpacity,n*=r.opacity,r.fill instanceof f&&void 0!==r.fill.color.a&&(n*=r.fill.color.a),a*=r.strokeOpacity,a*=r.opacity,r.stroke instanceof f&&void 0!==r.stroke.color.a&&(a*=r.stroke.color.a);var s,o={};if(o.opacity=n,o["stroke-opacity"]=a,i.setGState(new e(o)),r.fill&&r.fill instanceof f&&r.fill.color.ok?i.setFillColor(r.fill.color.r,r.fill.color.g,r.fill.color.b):i.setFillColor(0,0,0),i.setLineWidth(r.strokeWidth),r.stroke instanceof f?i.setDrawColor(r.stroke.color.r,r.stroke.color.g,r.stroke.color.b):i.setDrawColor(0,0,0),i.setLineCap(r.strokeLinecap),i.setLineJoin(r.strokeLinejoin),r.strokeDasharray?i.setLineDashPattern(r.strokeDasharray,r.strokeDashoffset):i.setLineDashPattern([],0),i.setLineMiterLimit(r.strokeMiterlimit),s=W.hasOwnProperty(r.fontFamily)?W[r.fontFamily]:r.fontFamily,r.fill&&r.fill instanceof f&&r.fill.color.ok){var l=r.fill.color;i.setTextColor(l.r,l.g,l.b)}else i.setTextColor(0,0,0);var u="";"bold"===r.fontWeight&&(u="bold"),"italic"===r.fontStyle&&(u+="italic"),""===u&&(u="normal"),void 0!==s||void 0!==u?(void 0===s&&(s=W.hasOwnProperty(r.fontFamily)?W[r.fontFamily]:r.fontFamily),i.setFont(s,u)):i.setFont("helvetica",u),i.setFontSize(r.fontSize*i.internal.scaleFactor)}(n=new p(t.pdf,{refsHandler:t.refsHandler,styleSheets:t.styleSheets,viewport:t.viewport,svg2pdfParameters:t.svg2pdfParameters,textMeasure:t.textMeasure})),a=0,s=this.children,o.label=1;case 1:return a<s.length?[4,s[a].render(n)]:[3,4];case 2:o.sent(),o.label=3;case 3:return a++,[3,1];case 4:return t.pdf.endFormObject(this.element.getAttribute("id")),[2]}}))}))},r.prototype.getBoundingBoxCore=function(t){var e,r=this.element.getAttribute("viewBox");return r&&(e=I(r)),[e&&e[0]||0,e&&e[1]||0,e&&e[2]||parseFloat(this.element.getAttribute("markerWidth")||"3"),e&&e[3]||parseFloat(this.element.getAttribute("markerHeight")||"3")]},r.prototype.computeNodeTransformCore=function(t){var e,r=parseFloat(this.element.getAttribute("refX")||"0"),i=parseFloat(this.element.getAttribute("refY")||"0"),n=this.element.getAttribute("viewBox");if(n){var a=I(n);e=Y(this.element,a,0,0,parseFloat(this.element.getAttribute("markerWidth")||"3"),parseFloat(this.element.getAttribute("markerHeight")||"3"),t,!0),e=t.pdf.matrixMult(t.pdf.Matrix(1,0,0,1,-r,-i),e)}else e=t.pdf.Matrix(1,0,0,1,-r,-i);return e},r.prototype.isVisible=function(t,e){return P(this,t,e)},r}($),ie=function(t){function e(e,r){return t.call(this,e,r)||this}return s(e,t),e.prototype.getR=function(t){var e;return null!==(e=this.r)&&void 0!==e?e:this.r=parseFloat(T(this.element,t.styleSheets,"r")||"0")},e.prototype.getRx=function(t){return this.getR(t)},e.prototype.getRy=function(t){return this.getR(t)},e}(vt),ne=function(t){function e(e,r){return t.call(this,!1,e,r)||this}return s(e,t),e}(Jt),ae=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return s(e,t),e.prototype.renderCore=function(t){return l(this,void 0,void 0,(function(){var e,r;return u(this,(function(i){switch(i.label){case 0:e=0,r=this.children,i.label=1;case 1:return e<r.length?[4,r[e].render(t)]:[3,4];case 2:i.sent(),i.label=3;case 3:return e++,[3,1];case 4:return[2]}}))}))},e.prototype.getBoundingBoxCore=function(t){return U(t,this)},e}(lt),se=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return s(e,t),e.prototype.isVisible=function(t,e){return P(this,t,e)},e.prototype.render=function(e){return l(this,void 0,void 0,(function(){var r,i,n,a,s;return u(this,(function(o){switch(o.label){case 0:return this.isVisible("hidden"!==e.attributeState.visibility,e)?(r=this.getX(e),i=this.getY(e),n=this.getWidth(e),a=this.getHeight(e),e.pdf.saveGraphicsState(),s=e.transform,this.element.hasAttribute("transform")&&(s=e.pdf.matrixMult(X(this.element.getAttribute("transform"),e),s)),e.pdf.setCurrentTransformationMatrix(s),e.withinUse||"visible"===T(this.element,e.styleSheets,"overflow")||e.pdf.rect(r,i,n,a).clip().discardPath(),[4,t.prototype.render.call(this,e.clone({transform:e.pdf.unitMatrix,viewport:e.withinUse?e.viewport:new dt(n,a)}))]):[2];case 1:return o.sent(),e.pdf.restoreGraphicsState(),[2]}}))}))},e.prototype.computeNodeTransform=function(t){return this.computeNodeTransformCore(t)},e.prototype.computeNodeTransformCore=function(t){if(t.withinUse)return t.pdf.unitMatrix;var e,r=this.getX(t),i=this.getY(t),n=this.getViewBox();if(n){var a=this.getWidth(t),s=this.getHeight(t);e=Y(this.element,n,r,i,a,s,t)}else e=t.pdf.Matrix(1,0,0,1,r,i);return e},e.prototype.getWidth=function(t){if(void 0!==this.width)return this.width;var e,r,i=t.svg2pdfParameters;if(this.isOutermostSvg(t))if(null!=i.width)e=i.width;else if(r=T(this.element,t.styleSheets,"width"))e=parseFloat(r);else{var n=this.getViewBox();if(n&&(null!=i.height||T(this.element,t.styleSheets,"height"))){var a=n[2]/n[3];e=this.getHeight(t)*a}else e=Math.min(300,t.viewport.width,2*t.viewport.height)}else e=(r=T(this.element,t.styleSheets,"width"))?parseFloat(r):t.viewport.width;return this.width=e},e.prototype.getHeight=function(t){if(void 0!==this.height)return this.height;var e,r,i=t.svg2pdfParameters;if(this.isOutermostSvg(t))if(null!=i.height)e=i.height;else if(r=T(this.element,t.styleSheets,"height"))e=parseFloat(r);else{var n=this.getViewBox();if(n){var a=n[2]/n[3];e=this.getWidth(t)/a}else e=Math.min(150,t.viewport.width/2,t.viewport.height)}else e=(r=T(this.element,t.styleSheets,"height"))?parseFloat(r):t.viewport.height;return this.height=e},e.prototype.getX=function(t){if(void 0!==this.x)return this.x;if(this.isOutermostSvg(t))return this.x=0;var e=T(this.element,t.styleSheets,"x");return this.x=e?parseFloat(e):0},e.prototype.getY=function(t){if(void 0!==this.y)return this.y;if(this.isOutermostSvg(t))return this.y=0;var e=T(this.element,t.styleSheets,"y");return this.y=e?parseFloat(e):0},e.prototype.getViewBox=function(){if(void 0!==this.viewBox)return this.viewBox;var t=this.element.getAttribute("viewBox");return this.viewBox=t?I(t):void 0},e.prototype.isOutermostSvg=function(t){return t.svg2pdfParameters.element===this.element},e}(ae),oe=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return s(e,t),e.prototype.isVisible=function(t,e){return P(this,t,e)},e.prototype.computeNodeTransformCore=function(t){return t.pdf.unitMatrix},e}(ae),le=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return s(e,t),e.prototype.apply=function(t){return l(this,void 0,void 0,(function(){var e,r,i;return u(this,(function(n){switch(n.label){case 0:if(!this.isVisible(!0,t))return[2];e=t.pdf.matrixMult(this.computeNodeTransform(t),t.transform),t.pdf.setCurrentTransformationMatrix(e),r=0,i=this.children,n.label=1;case 1:return r<i.length?[4,i[r].render(new p(t.pdf,{refsHandler:t.refsHandler,styleSheets:t.styleSheets,viewport:t.viewport,withinClipPath:!0,svg2pdfParameters:t.svg2pdfParameters,textMeasure:t.textMeasure}))]:[3,4];case 2:n.sent(),n.label=3;case 3:return r++,[3,1];case 4:return t.pdf.clip().discardPath(),t.pdf.setCurrentTransformationMatrix(e.inversed()),[2]}}))}))},e.prototype.getBoundingBoxCore=function(t){return U(t,this)},e.prototype.isVisible=function(t,e){return P(this,t,e)},e}($);function ue(t,e){var r,i=[];switch(function(t,e){for(var r=[],i=0;i<t.childNodes.length;i++){var n=t.childNodes[i];"#"!==n.nodeName.charAt(0)&&r.push(n)}for(i=0;i<r.length;i++)e(i,r[i])}(t,(function(t,r){return i.push(ue(r,e))})),t.tagName.toLowerCase()){case"a":case"g":r=new oe(t,i);break;case"circle":r=new ie(t,i);break;case"clippath":r=new le(t,i);break;case"ellipse":r=new yt(t,i);break;case"lineargradient":r=new Z(t,i);break;case"image":r=new Zt(t,i);break;case"line":r=new ct(t,i);break;case"marker":r=new re(t,i);break;case"path":r=new $t(t,i);break;case"pattern":r=new et(t,i);break;case"polygon":r=new te(t,i);break;case"polyline":r=new ne(t,i);break;case"radialgradient":r=new J(t,i);break;case"rect":r=new gt(t,i);break;case"svg":r=new se(t,i);break;case"symbol":r=new pt(t,i);break;case"text":r=new Ct(t,i);break;case"use":r=new mt(t,i);break;default:r=new ee(t,i)}if(null!=e&&r.element.hasAttribute("id")){var n=r.element.id;e[n]=e[n]||r}return r.children.forEach((function(t){return t.setParent(r)})),r}var he=function(){function t(t,e){this.rootSvg=t,this.loadExternalSheets=e,this.styleSheets=[]}return t.prototype.load=function(){return l(this,void 0,void 0,(function(){var t;return u(this,(function(e){switch(e.label){case 0:return[4,this.collectStyleSheetTexts()];case 1:return t=e.sent(),this.parseCssSheets(t),[2]}}))}))},t.prototype.collectStyleSheetTexts=function(){return l(this,void 0,void 0,(function(){var e,r,i,n,a;return u(this,(function(s){switch(s.label){case 0:if(e=[],this.loadExternalSheets&&this.rootSvg.ownerDocument)for(n=0;n<this.rootSvg.ownerDocument.childNodes.length;n++)"xml-stylesheet"===(r=this.rootSvg.ownerDocument.childNodes[n]).nodeName&&"string"==typeof r.data&&e.push(t.loadSheet(r.data.match(/href=["'].*?["']/)[0].split("=")[1].slice(1,-1)));for(i=this.rootSvg.querySelectorAll("style,link"),n=0;n<i.length;n++)F(a=i[n],"style")?e.push(a.textContent):this.loadExternalSheets&&F(a,"link")&&"stylesheet"===a.getAttribute("rel")&&a.hasAttribute("href")&&e.push(t.loadSheet(a.getAttribute("href")));return[4,Promise.all(e)];case 1:return[2,s.sent().filter((function(t){return null!==t}))]}}))}))},t.prototype.parseCssSheets=function(e){for(var r=document.implementation.createHTMLDocument(""),i=0,n=e;i<n.length;i++){var a=n[i],s=r.createElement("style");s.textContent=a,r.body.appendChild(s);var o=s.sheet;if(o instanceof CSSStyleSheet){for(var l=o.cssRules.length-1;l>=0;l--){var u=o.cssRules[l];if(u instanceof CSSStyleRule){var h=u;if(h.selectorText.indexOf(",")>=0){o.deleteRule(l);for(var f=h.cssText.substring(h.selectorText.length),c=t.splitSelectorAtCommas(h.selectorText),p=0;p<c.length;p++)o.insertRule(c[p]+f,l+p)}}else o.deleteRule(l)}this.styleSheets.push(o)}}},t.splitSelectorAtCommas=function(t){for(var e,r=/,|["']/g,i=/[^\\]["]/g,n=/[^\\][']/g,a=[],s="initial",o=-1,l=i,u=0;u<t.length;)switch(s){case"initial":r.lastIndex=u,(e=r.exec(t))?(","===e[0]?(a.push(t.substring(o+1,r.lastIndex-1).trim()),o=r.lastIndex-1):(s="withinQuotes",l='"'===e[0]?i:n),u=r.lastIndex):(a.push(t.substring(o+1).trim()),u=t.length);break;case"withinQuotes":l.lastIndex=u,(e=l.exec(t))&&(u=l.lastIndex,s="initial")}return a},t.loadSheet=function(t){return new Promise((function(e,r){var i=new XMLHttpRequest;i.open("GET",t,!0),i.responseType="text",i.onload=function(){200!==i.status&&r(new Error("Error "+i.status+": Failed to load '"+t+"'")),e(i.responseText)},i.onerror=r,i.onabort=r,i.send(null)})).catch((function(){return null}))},t.prototype.getPropertyValue=function(t,e){for(var r=[],i=0,n=this.styleSheets;i<n.length;i++)for(var a=n[i],s=0;s<a.cssRules.length;s++){var o=a.cssRules[s];o.style.getPropertyValue(e)&&t.matches(o.selectorText)&&r.push(o)}if(0!==r.length){return r.reduce((function(t,r){return 1==(n=r,(a=(i=t).style.getPropertyPriority(e))!==n.style.getPropertyPriority(e)?"important"===a?1:-1:(console.log("removed specificity check ",i.selectorText,n.selectorText),0))?t:r;var i,n,a})).style.getPropertyValue(e)||void 0}},t}(),fe=function(){function t(){this.measureMethods={}}return t.prototype.getTextOffset=function(t,e){var r=e.textAnchor;if("start"===r)return 0;var i=this.measureTextWidth(t,e),n=0;switch(r){case"end":n=i;break;case"middle":n=i/2}return n},t.prototype.measureTextWidth=function(t,e){if(0===t.length)return 0;var r=e.fontFamily;return this.getMeasureFunction(r).call(this,t,e.fontFamily,e.fontSize+"px",e.fontStyle,e.fontWeight)},t.prototype.getMeasurementTextNode=function(){if(!this.textMeasuringTextElement){this.textMeasuringTextElement=document.createElementNS("http://www.w3.org/2000/svg","text");var t=document.createElementNS("http://www.w3.org/2000/svg","svg");t.appendChild(this.textMeasuringTextElement),t.style.setProperty("position","absolute"),t.style.setProperty("visibility","hidden"),document.body.appendChild(t)}return this.textMeasuringTextElement},t.prototype.canvasTextMeasure=function(t,e,r,i,n){var a=document.createElement("canvas").getContext("2d");return null!=a?(a.font=[i,n,r,e].join(" "),a.measureText(t).width):0},t.prototype.svgTextMeasure=function(t,e,r,i,n,a){void 0===a&&(a=this.getMeasurementTextNode());var s=a;return s.setAttribute("font-family",e),s.setAttribute("font-size",r),s.setAttribute("font-style",i),s.setAttribute("font-weight",n),s.setAttributeNS("http://www.w3.org/XML/1998/namespace","xml:space","preserve"),s.textContent=t,s.getBBox().width},t.prototype.getMeasureFunction=function(e){var r=this.measureMethods[e];if(!r){var i=this.canvasTextMeasure(t.testString,e,"16px","normal","normal"),n=this.svgTextMeasure(t.testString,e,"16px","normal","normal");r=Math.abs(i-n)<t.epsilon?this.canvasTextMeasure:this.svgTextMeasure,this.measureMethods[e]=r}return r},t.prototype.cleanupTextMeasuring=function(){if(this.textMeasuringTextElement){var t=this.textMeasuringTextElement.parentNode;t&&document.body.removeChild(t),this.textMeasuringTextElement=void 0}},t.testString="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ 0123456789!\"$%&/()=?'\\+*-_.:,;^}][{#~|<>",t.epsilon=.1,t}();function ce(t,e,r){var i,n,a;return void 0===r&&(r={}),l(this,void 0,void 0,(function(){var s,l,h,f,c,m,g,v,y,b,x;return u(this,(function(u){switch(u.label){case 0:return s=null!==(i=r.x)&&void 0!==i?i:0,l=null!==(n=r.y)&&void 0!==n?n:0,h=null!==(a=r.loadExternalStyleSheets)&&void 0!==a&&a,c=new d(f={}),[4,(m=new he(t,h)).load()];case 1:return u.sent(),g=new dt(e.internal.pageSize.getWidth(),e.internal.pageSize.getHeight()),v=o(o({},r),{element:t}),y=new fe,b=new p(e,{refsHandler:c,styleSheets:m,viewport:g,svg2pdfParameters:v,textMeasure:y}),e.advancedAPI(),e.saveGraphicsState(),e.setCurrentTransformationMatrix(e.Matrix(1,0,0,1,s,l)),e.setLineWidth(b.attributeState.strokeWidth),x=b.attributeState.fill.color,e.setFillColor(x.r,x.g,x.b),e.setFont(b.attributeState.fontFamily),e.setFontSize(b.attributeState.fontSize*e.internal.scaleFactor),[4,ue(t,f).render(b)];case 2:return u.sent(),e.restoreGraphicsState(),e.compatAPI(),b.textMeasure.cleanupTextMeasuring(),[2,e]}}))}))}n.API.svg=function(t,e){return void 0===e&&(e={}),ce(t,this,e)};export{ce as svg2pdf};
