painter-web
Version:
为H5提供的painter
16 lines (13 loc) • 31 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).PainterWeb=e()}(this,(function(){"use strict";
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */function t(t,e,r,i){return new(r||(r=Promise))((function(s,o){function n(t){try{a(i.next(t))}catch(t){o(t)}}function c(t){try{a(i.throw(t))}catch(t){o(t)}}function a(t){var e;t.done?s(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(n,c)}a((i=i.apply(t,e||[])).next())}))}var e={563:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.default=function t(e){e=e.trim();for(var r=new Array,i="+",s="",o=e.length,n=0;n<o;++n){if("."===e[n]||!isNaN(Number(e[n]))&&" "!==e[n])s+=e[n];else if("("===e[n]){for(var c=1,a=n;c>0;)"("===e[a+=1]&&(c+=1),")"===e[a]&&(c-=1);s=""+t(e.slice(n+1,a)),n=a}if(isNaN(Number(e[n]))&&"."!==e[n]||n===o-1){var h=parseFloat(s);switch(i){case"+":r.push(h);break;case"-":r.push(-h);break;case"*":r.push(r.pop()*h);break;case"/":r.push(r.pop()/h)}i=e[n],s=""}}for(var l=0;r.length;)l+=r.pop();return l}},834:(t,e)=>{function r(t){for(var e=[],r=[],i=0,s=t.substring(0,t.length-1).split("%,");i<s.length;i++){var o=s[i];e.push(o.substring(0,o.lastIndexOf(" ")).trim()),r.push(parseInt(o.slice(o.lastIndexOf(" ")))/100)}return{colors:e,percents:r}}Object.defineProperty(e,"__esModule",{value:!0}),e.doGradient=e.isGradient=void 0,e.isGradient=function(t){return!(!t||!t.startsWith("linear")&&!t.startsWith("radial"))},e.doGradient=function(t,e,i,s){t.startsWith("linear")?function(t,e,i,s){var o=function(t,e,r){var i,s=t.match(/([-]?\d{1,3})deg/),o=s&&s[1]?parseFloat(s[1]):0;switch(o){case 0:i=[0,-r/2,0,r/2];break;case 90:i=[e/2,0,-e/2,0];break;case-90:i=[-e/2,0,e/2,0];break;case 180:i=[0,r/2,0,-r/2];break;case-180:i=[0,-r/2,0,r/2];break;default:var n=0,c=0,a=0,h=0;o>0&&o<90?(a=-(n=e/2-(e/2*Math.tan((90-o)*Math.PI*2/360)-r/2)*Math.sin(2*(90-o)*Math.PI*2/360)/2),c=-(h=Math.tan((90-o)*Math.PI*2/360)*n)):o>-180&&o<-90?(a=-(n=-e/2+(e/2*Math.tan((90-o)*Math.PI*2/360)-r/2)*Math.sin(2*(90-o)*Math.PI*2/360)/2),c=-(h=Math.tan((90-o)*Math.PI*2/360)*n)):o>90&&o<180?(a=-(n=e/2+(-e/2*Math.tan((90-o)*Math.PI*2/360)-r/2)*Math.sin(2*(90-o)*Math.PI*2/360)/2),c=-(h=Math.tan((90-o)*Math.PI*2/360)*n)):(a=-(n=-e/2-(-e/2*Math.tan((90-o)*Math.PI*2/360)-r/2)*Math.sin(2*(90-o)*Math.PI*2/360)/2),c=-(h=Math.tan((90-o)*Math.PI*2/360)*n)),i=[n,c,a,h]}return i}(i,t,e),n=s.createLinearGradient(o[0],o[1],o[2],o[3]),c=i.match(/linear-gradient\((.+)\)/);if(c){for(var a=c[1],h=r(a.substring(a.indexOf(",")+1)),l=0;l<h.colors.length;l++)n.addColorStop(h.percents[l],h.colors[l]);s.fillStyle=n}}(e,i,t,s):t.startsWith("radial")&&function(t,e,i,s){var o=i.match(/radial-gradient\((.+)\)/);if(o){for(var n=r(o[1]),c=s.createRadialGradient(0,0,0,0,0,t<e?e/2:t/2),a=0;a<n.colors.length;a++)c.addColorStop(n.percents[a],n.colors[a]);s.fillStyle=c}}(e,i,t,s)}},779:function(t,e,r){var i=this&&this.__assign||function(){return(i=Object.assign||function(t){for(var e,r=1,i=arguments.length;r<i;r++)for(var s in e=arguments[r])Object.prototype.hasOwnProperty.call(e,s)&&(t[s]=e[s]);return t}).apply(this,arguments)},s=this&&this.__awaiter||function(t,e,r,i){return new(r||(r=Promise))((function(s,o){function n(t){try{a(i.next(t))}catch(t){o(t)}}function c(t){try{a(i.throw(t))}catch(t){o(t)}}function a(t){var e;t.done?s(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(n,c)}a((i=i.apply(t,e||[])).next())}))},o=this&&this.__generator||function(t,e){var r,i,s,o,n={label:0,sent:function(){if(1&s[0])throw s[1];return s[1]},trys:[],ops:[]};return o={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function c(o){return function(c){return function(o){if(r)throw new TypeError("Generator is already executing.");for(;n;)try{if(r=1,i&&(s=2&o[0]?i.return:o[0]?i.throw||((s=i.return)&&s.call(i),0):i.next)&&!(s=s.call(i,o[1])).done)return s;switch(i=0,s&&(o=[2&o[0],s.value]),o[0]){case 0:case 1:s=o;break;case 4:return n.label++,{value:o[1],done:!1};case 5:n.label++,i=o[1],o=[0];continue;case 7:o=n.ops.pop(),n.trys.pop();continue;default:if(!((s=(s=n.trys).length>0&&s[s.length-1])||6!==o[0]&&2!==o[0])){n=0;continue}if(3===o[0]&&(!s||o[1]>s[0]&&o[1]<s[3])){n.label=o[1];break}if(6===o[0]&&n.label<s[1]){n.label=s[1],s=o;break}if(s&&n.label<s[2]){n.label=s[2],n.ops.push(o);break}s[2]&&n.ops.pop(),n.trys.pop();continue}o=e.call(t,n)}catch(t){o=[6,t],i=0}finally{r=s=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,c])}}};Object.defineProperty(e,"__esModule",{value:!0}),e.Pen=e.clearPenCache=e.penCache=void 0;var n=r(536),c=r(834),a=r(593);e.penCache={viewRect:{},textLines:{}},e.clearPenCache=function(t){t?(e.penCache.viewRect[t]=null,e.penCache.textLines[t]=null):(e.penCache.viewRect={},e.penCache.textLines={})};var h=function(){function t(t,e){this.ctx=t,this.data=e,this.ctx=t,this.data=e,this.style={width:0,height:0}}return t.prototype.paint=function(t){return s(this,void 0,void 0,(function(){var e,r,i;return o(this,(function(s){switch(s.label){case 0:return this.style={width:a.toPx(this.data.width),height:a.toPx(this.data.height)},[4,this._background()];case 1:s.sent(),e=0,r=this.data.views,s.label=2;case 2:return e<r.length?(i=r[e],[4,this._drawAbsolute(i)]):[3,5];case 3:s.sent(),s.label=4;case 4:return e++,[3,2];case 5:return t&&t(),[2]}}))}))},t.prototype._background=function(){return s(this,void 0,void 0,(function(){var t,e,r,i,s;return o(this,(function(o){switch(o.label){case 0:return this.ctx.save(),t=this.style,e=t.width,r=t.height,i=this.data.background,this.ctx.translate(e/2,r/2),this._doClip(this.data.borderRadius,e,r),i?[3,1]:(this.ctx.fillStyle="transparent",this.ctx.fillRect(-e/2,-r/2,e,r),[3,5]);case 1:return i.startsWith("#")||i.startsWith("rgba")||"transparent"===i.toLowerCase()?(this.ctx.fillStyle=i,this.ctx.fillRect(-e/2,-r/2,e,r),[3,5]):[3,2];case 2:return c.isGradient(i)?(c.doGradient(i,e,r,this.ctx),this.ctx.fillRect(-e/2,-r/2,e,r),[3,5]):[3,3];case 3:return[4,a.injection.loadImage(i)];case 4:(s=o.sent().img)&&this.ctx.drawImage(s,-e/2,-r/2,e,r),o.label=5;case 5:return this.ctx.restore(),[2]}}))}))},t.prototype._drawAbsolute=function(t){var r=this;return new Promise((function(n){return s(r,void 0,void 0,(function(){var r;return o(this,(function(s){switch(s.label){case 0:if(!t||!t.type)return[2];switch(Array.isArray(t.css)&&(t.css=Object.assign.apply(Object,t.css)),t.type){case"image":return[3,1];case"text":return[3,3];case"rect":return[3,5];case"qrcode":return[3,7]}return[3,9];case 1:return[4,this._drawAbsImage(t)];case 2:return s.sent(),[3,13];case 3:return[4,this._fillAbsText(t)];case 4:return s.sent(),[3,13];case 5:return[4,this._drawAbsRect(t)];case 6:return s.sent(),[3,13];case 7:return[4,this._drawQRCode(t)];case 8:return s.sent(),[3,13];case 9:return a.injection.customActions[t.type]?(r=a.injection.customActions[t.type].layout(t,JSON.parse(JSON.stringify(e.penCache.viewRect||{}))),t.rect=i(i({},r),{height:r.bottom-r.top,width:r.right-r.left}),t.id&&(e.penCache.viewRect[t.id]=JSON.parse(JSON.stringify(t.rect))),this.ctx.save(),[4,a.injection.customActions[t.type].draw(t,this.ctx)]):[3,11];case 10:return s.sent(),this.ctx.restore(),[3,12];case 11:console.log("ignore",t.type),s.label=12;case 12:return[3,13];case 13:return n(),[2]}}))}))}))},t.prototype._border=function(t){var e=t.borderRadius,r=void 0===e?0:e,i=t.width,s=t.height,o=t.borderWidth,n=void 0===o?0:o,c=t.borderStyle,h=void 0===c?"solid":c,l=0,d=0,f=0,u=0,x=Math.min(i,s);if(r)if("string"==typeof r){var p=r.split(/\s+/);4===p.length?(l=Math.min(a.toPx(p[0],x),i/2,s/2),d=Math.min(a.toPx(p[1],x),i/2,s/2),f=Math.min(a.toPx(p[2],x),i/2,s/2),u=Math.min(a.toPx(p[3],x),i/2,s/2)):l=d=f=u=Math.min(a.toPx(p[0],x),i/2,s/2)}else l=d=f=u=Math.min(a.toPx(r),i/2,s/2);var g=n?a.toPx(n,x):0;this.ctx.lineWidth=g,"dashed"===h?this.ctx.setLineDash([4*g/3,4*g/3]):"dotted"===h&&this.ctx.setLineDash([g,g]);var v="solid"!==h;this.ctx.beginPath(),v&&0===l&&this.ctx.moveTo(-i/2-g,-s/2-g/2),0!==l&&this.ctx.arc(-i/2+l,-s/2+l,l+g/2,1*Math.PI,1.5*Math.PI),this.ctx.lineTo(0===d?v?i/2:i/2+g/2:i/2-d,-s/2-g/2),v&&0===d&&this.ctx.moveTo(i/2+g/2,-s/2-g),0!==d&&this.ctx.arc(i/2-d,-s/2+d,d+g/2,1.5*Math.PI,2*Math.PI),this.ctx.lineTo(i/2+g/2,0===f?v?s/2:s/2+g/2:s/2-f),v&&0===f&&this.ctx.moveTo(i/2+g,s/2+g/2),0!==f&&this.ctx.arc(i/2-f,s/2-f,f+g/2,0,.5*Math.PI),this.ctx.lineTo(0===u?v?-i/2:-i/2-g/2:-i/2+u,s/2+g/2),v&&0===u&&this.ctx.moveTo(-i/2-g/2,s/2+g),0!==u&&this.ctx.arc(-i/2+u,s/2-u,u+g/2,.5*Math.PI,1*Math.PI),this.ctx.lineTo(-i/2-g/2,0===l?v?-s/2:-s/2-g/2:-s/2+l),v&&0===l&&this.ctx.moveTo(-i/2-g,-s/2-g/2),v||this.ctx.closePath()},t.prototype._doClip=function(t,e,r,i){t&&e&&r&&(this.ctx.globalAlpha=0,this.ctx.fillStyle="white",this._border({borderRadius:t,width:e,height:r,borderStyle:i}),this.ctx.fill(),this.ctx.clip(),this.ctx.globalAlpha=1)},t.prototype._doBorder=function(t,e,r){if(t.css){var i=t.css,s=i.borderRadius,o=i.borderWidth,n=i.borderColor,c=i.borderStyle;o&&(this.ctx.save(),this._preProcess(t,!0),this.ctx.strokeStyle=n||"black",this._border({borderRadius:s,width:e,height:r,borderWidth:o,borderStyle:c}),this.ctx.stroke(),this.ctx.restore())}},t.prototype._preProcess=function(t,r){var i,s,o,n,c=0,h=this._doPaddings(t);switch(t.type){case"text":for(var l=String(t.text).split("\n"),d=0;d<l.length;++d)""===l[d]&&(l[d]=" ");var f=t.css.fontWeight||"400",u=t.css.fontStyle||"italic"===t.css.textStyle||"oblique"===t.css.textStyle?t.css.textStyle:"normal";t.css.fontSize||(t.css.fontSize="20rpx");var x=a.toPx(t.css.fontSize);this.ctx.font=u+" "+f+" "+x+'px "'+(t.css.fontFamily||"sans-serif")+'"';var p=0,g=[];for(d=0;d<l.length;++d){var v=this.ctx.measureText(l[d]).width,b=x+h[1]+h[3],y=t.css.width?a.toPx(t.css.width,this.style.width)-h[1]-h[3]:v;y<b&&(y=b);var w=Math.ceil(v/y);c=y>c?y:c,p+=w,g[d]=w}p="number"==typeof t.css.maxLines&&t.css.maxLines<p?t.css.maxLines:p;var P=t.css.lineHeight?a.toPx(t.css.lineHeight):a.toPx(t.css.fontSize);i=P*p,s={lines:p,lineHeight:P,textArray:l,linesArray:g};break;case"image":var m=a.injection.getRatio();t.css&&(t.css.width||(t.css.width="auto"),t.css.height||(t.css.height="auto")),!t.css||"auto"===t.css.width&&"auto"===t.css.height?(c=Math.round(t.sWidth/m),i=Math.round(t.sHeight/m)):"auto"===t.css.width?(i=a.toPx(t.css.height,this.style.height),c=t.sWidth/t.sHeight*i):"auto"===t.css.height?(c=a.toPx(t.css.width,this.style.width),i=t.sHeight/t.sWidth*c):(c=a.toPx(t.css.width,this.style.width),i=a.toPx(t.css.height,this.style.height));break;default:if(!t.css.width||!t.css.height)return void console.error("You should set width and height");c=a.toPx(t.css.width,this.style.width),i=a.toPx(t.css.height,this.style.height)}if(t.css&&t.css.right)if("string"==typeof t.css.right)o=this.style.width-a.toPx(t.css.right,this.style.width);else{var _=t.css.right;o=this.style.width-a.toPx(_[0],this.style.width)-(e.penCache.viewRect[_[1]]?e.penCache.viewRect[_[1]].width*(_[2]||1):0)}else if(t.css&&t.css.left)if("string"==typeof t.css.left)o=a.toPx(t.css.left,this.style.width);else{var S=t.css.left;o=a.toPx(S[0],this.style.width)+(e.penCache.viewRect[S[1]]?e.penCache.viewRect[S[1]].width*(S[2]||1):0)}else o=0;if(t.css&&t.css.bottom)n=this.style.height-i-a.toPx(t.css.bottom,this.style.height);else if(t.css&&t.css.top)if("string"==typeof t.css.top)n=a.toPx(t.css.top,this.style.height);else{var M=t.css.top;n=a.toPx(M[0],this.style.height)+(e.penCache.viewRect[M[1]]?e.penCache.viewRect[M[1]].height*(M[2]||1):0)}else n=0;var C=t.css&&t.css.rotate?this._getAngle(t.css.rotate):0,k=t.css&&t.css.align?t.css.align:t.css&&t.css.right?"right":"left",R=t.css&&t.css.verticalAlign?t.css.verticalAlign:"top",I=0;switch(k){case"center":I=o;break;case"right":I=o-c/2;break;default:I=o+c/2}var T=0;switch(R){case"center":T=n;break;case"bottom":T=n-i/2;break;default:T=n+i/2}this.ctx.translate(I,T);var j=o;"center"===k?j=o-c/2:"right"===k&&(j=o-c);var A=n;return"center"===R?A=n-i/2:"bottom"===R&&(A=n-i),t.rect?(t.rect.left=j,t.rect.top=A,t.rect.right=j+c,t.rect.bottom=A+i,t.rect.x=t.css&&t.css.right?o-c:o,t.rect.y=n):t.rect={left:j,top:A,right:j+c,bottom:A+i,x:t.css&&t.css.right?o-c:o,y:n},t.rect.left=t.rect.left-h[3],t.rect.top=t.rect.top-h[0],t.rect.right=t.rect.right+h[1],t.rect.bottom=t.rect.bottom+h[2],"text"===t.type&&(t.rect.minWidth=a.toPx(t.css.fontSize)+h[1]+h[3]),this.ctx.rotate(C),!r&&t.css&&t.css.borderRadius&&"rect"!==t.type&&this._doClip(t.css.borderRadius,c,i,t.css.borderStyle),this._doShadow(t),t.id&&(e.penCache.viewRect[t.id]={width:c,height:i,left:o,top:n,right:o+c,bottom:n+i}),{width:c,height:i,x:o,y:n,extra:s}},t.prototype._doPaddings=function(t){var e=(t.css?t.css:{}).padding,r=void 0===e?"":e,i=[0,0,0,0];if(r)if("string"==typeof r){var s,o,n=r.split(/\s+/);1===n.length&&(i=[s=a.toPx(n[0]),s,s,s]),2===n.length&&(i=[s=a.toPx(n[0]),o=a.toPx(n[1]),s,o]),3===n.length&&(i=[s=a.toPx(n[0]),o=a.toPx(n[1]),a.toPx(n[2]),o]),4===n.length&&(i=[s=a.toPx(n[0]),o=a.toPx(n[1]),a.toPx(n[2]),a.toPx(n[3])])}else i=[r,r,r,r];return i},t.prototype._doBackground=function(t){this.ctx.save();var e=this._preProcess(t,!0),r=e.width,i=e.height,s=t.css.background,o=this._doPaddings(t),n=r+o[1]+o[3],a=i+o[0]+o[2];this._doClip(t.css.borderRadius,n,a,t.css.borderStyle),c.isGradient(String(s))?c.doGradient(String(s),n,a,this.ctx):this.ctx.fillStyle=String(s),this.ctx.fillRect(-n/2,-a/2,n,a),this.ctx.restore()},t.prototype._drawQRCode=function(t){this.ctx.save();var e=this._preProcess(t),r=e.width,i=e.height;n.api.draw(t.content,this.ctx,-r/2,-i/2,r,i,t.css.background?String(t.css.background):"",t.css.color),this.ctx.restore(),this._doBorder(t,r,i)},t.prototype._drawAbsImage=function(t){return s(this,void 0,void 0,(function(){var e,r,i,s,n,c,h,l,d,f,u,x,p;return o(this,(function(o){switch(o.label){case 0:return t.url?(this.ctx.save(),[4,a.injection.loadImage(t.url)]):[2];case 1:return e=o.sent(),r=e.img,i=e.width,s=e.height,t.sHeight=s,t.sWidth=i,r?(n=this._preProcess(t),c=n.width,h=n.height,l=t.sWidth,d=t.sHeight,f=0,u=0,x=c/h,p=t.sWidth/t.sHeight,x>=p?(d=l/x,u=Math.round((t.sHeight-d)/2)):(l=d*x,f=Math.round((t.sWidth-l)/2)),t.css&&"scaleToFill"===t.css.mode?this.ctx.drawImage(r,-c/2,-h/2,c,h):(this.ctx.drawImage(r,f,u,l,d,-c/2,-h/2,c,h),t.rect.startX=f/t.sWidth,t.rect.startY=u/t.sHeight,t.rect.endX=(f+l)/t.sWidth,t.rect.endY=(u+d)/t.sHeight),this.ctx.restore(),this._doBorder(t,c,h),[2]):[2]}}))}))},t.prototype._fillAbsText=function(t){var r,i;if(t.text){t.css.background&&this._doBackground(t),this.ctx.save();var s=this._preProcess(t,Boolean(t.css.background&&t.css.borderRadius)),o=s.width,n=s.height,c=s.extra;if(this.ctx.fillStyle=t.css.color||"black",t.id&&e.penCache.textLines[t.id]){this.ctx.textAlign=t.css.textAlign?t.css.textAlign:"left";for(var h=0,l=e.penCache.textLines[t.id];h<l.length;h++){var d=(_=l[h]).measuredWith,f=_.text,u=_.x,x=_.y,p=_.textDecoration;if("stroke"===t.css.textStyle?this.ctx.strokeText(f,u,x,d):this.ctx.fillText(f,u,x,d),p){var g=a.toPx(t.css.fontSize);this.ctx.lineWidth=g/13,this.ctx.beginPath(),(r=this.ctx).moveTo.apply(r,p.moveTo),(i=this.ctx).lineTo.apply(i,p.lineTo),this.ctx.closePath(),this.ctx.strokeStyle=t.css.color,this.ctx.stroke()}}}else{var v=c,b=v.lines,y=v.lineHeight,w=v.textArray,P=v.linesArray;if(t.id){for(var m=0,_=0;_<w.length;++_){var S=this.ctx.measureText(w[_]).width;m=S>m?S:m}e.penCache.viewRect[t.id].width=o?m<o?m:o:m}for(var M=0,C=(g=a.toPx(t.css.fontSize),0);C<w.length;++C){var k=Math.ceil(w[C].length/P[C]),R=0,I=0;for(_=0;_<P[C]&&!(M>=b);++_){for(I=k,f=w[C].substr(R,I),d=this.ctx.measureText(f).width;R+I<=w[C].length&&(o-d>g||d-o>g);){if(d<o)f=w[C].substr(R,++I);else{if(f.length<=1)break;f=w[C].substr(R,--I)}d=this.ctx.measureText(f).width}if(R+=f.length,M===b-1&&(C<w.length-1||R<w[C].length)){for(;this.ctx.measureText(f+"...").width>o&&!(f.length<=1);)f=f.substring(0,f.length-1);f+="...",d=this.ctx.measureText(f).width}this.ctx.textAlign=t.css.textAlign?t.css.textAlign:"left",u=void 0;var T=void 0;switch(t.css.textAlign){case"center":T=(u=0)-d/2;break;case"right":T=(u=o/2)-d;break;default:T=u=-o/2}x=-n/2+(0===M?g:g+M*y),M++,"stroke"===t.css.textStyle?this.ctx.strokeText(f,u,x,d):this.ctx.fillText(f,u,x,d),p=void 0,t.css.textDecoration&&"string"==typeof t.css.textDecoration&&(this.ctx.lineWidth=g/13,this.ctx.beginPath(),/\bunderline\b/.test(t.css.textDecoration)&&(this.ctx.moveTo(T,x),this.ctx.lineTo(T+d,x),p={moveTo:[T,x],lineTo:[T+d,x]}),/\boverline\b/.test(t.css.textDecoration)&&(this.ctx.moveTo(T,x-g),this.ctx.lineTo(T+d,x-g),p={moveTo:[T,x-g],lineTo:[T+d,x-g]}),/\bline-through\b/.test(t.css.textDecoration)&&(this.ctx.moveTo(T,x-g/3),this.ctx.lineTo(T+d,x-g/3),p={moveTo:[T,x-g/3],lineTo:[T+d,x-g/3]}),this.ctx.closePath(),this.ctx.strokeStyle=t.css.color,this.ctx.stroke()),t.id&&(e.penCache.textLines[t.id]?e.penCache.textLines[t.id].push({text:f,x:u,y:x,measuredWith:d,textDecoration:p}):e.penCache.textLines[t.id]=[{text:f,x:u,y:x,measuredWith:d,textDecoration:p}])}}}this.ctx.restore(),this._doBorder(t,o,n)}},t.prototype._drawAbsRect=function(t){this.ctx.save();var e=this._preProcess(t),r=e.width,i=e.height;c.isGradient(t.css.color)?c.doGradient(t.css.color,r,i,this.ctx):this.ctx.fillStyle=t.css.color;var s=t.css,o=s.borderRadius,n=s.borderStyle,a=s.borderWidth;this._border({borderRadius:o,width:r,height:i,borderWidth:a,borderStyle:n}),this.ctx.fill(),this.ctx.restore(),this._doBorder(t,r,i)},t.prototype._doShadow=function(t){if(t.css&&(t.css.shadow||t.css.boxShadow)){var e=(t.css.boxShadow||t.css.shadow).replace(/,\s+/g,",").split(/\s+/);e.length>4?console.error("shadow don't spread option"):(this.ctx.shadowOffsetX=parseInt(e[0],10),this.ctx.shadowOffsetY=parseInt(e[1],10),this.ctx.shadowBlur=parseInt(e[2],10),this.ctx.shadowColor=e[3])}},t.prototype._getAngle=function(t){return Number(t)*Math.PI/180},t}();e.Pen=h},536:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.api=void 0;var r,i,s,o,n,c,a=[0,11,15,19,23,27,31,16,18,20,22,24,26,28,20,22,24,24,26,28,28,22,24,24,26,26,28,28,24,24,26,26,26,28,28,24,26,26,26,28,28],h=[3220,1468,2713,1235,3062,1890,2119,1549,2344,2936,1117,2583,1330,2470,1667,2249,2028,3780,481,4011,142,3098,831,3445,592,2517,1776,2234,1951,2827,1070,2660,1345,3177],l=[30660,29427,32170,30877,26159,25368,27713,26998,21522,20773,24188,23371,17913,16590,20375,19104,13663,12392,16177,14854,9396,8579,11994,11245,5769,5054,7399,6608,1890,597,3340,2107],d=[1,0,19,7,1,0,16,10,1,0,13,13,1,0,9,17,1,0,34,10,1,0,28,16,1,0,22,22,1,0,16,28,1,0,55,15,1,0,44,26,2,0,17,18,2,0,13,22,1,0,80,20,2,0,32,18,2,0,24,26,4,0,9,16,1,0,108,26,2,0,43,24,2,2,15,18,2,2,11,22,2,0,68,18,4,0,27,16,4,0,19,24,4,0,15,28,2,0,78,20,4,0,31,18,2,4,14,18,4,1,13,26,2,0,97,24,2,2,38,22,4,2,18,22,4,2,14,26,2,0,116,30,3,2,36,22,4,4,16,20,4,4,12,24,2,2,68,18,4,1,43,26,6,2,19,24,6,2,15,28,4,0,81,20,1,4,50,30,4,4,22,28,3,8,12,24,2,2,92,24,6,2,36,22,4,6,20,26,7,4,14,28,4,0,107,26,8,1,37,22,8,4,20,24,12,4,11,22,3,1,115,30,4,5,40,24,11,5,16,20,11,5,12,24,5,1,87,22,5,5,41,24,5,7,24,30,11,7,12,24,5,1,98,24,7,3,45,28,15,2,19,24,3,13,15,30,1,5,107,28,10,1,46,28,1,15,22,28,2,17,14,28,5,1,120,30,9,4,43,26,17,1,22,28,2,19,14,28,3,4,113,28,3,11,44,26,17,4,21,26,9,16,13,26,3,5,107,28,3,13,41,26,15,5,24,30,15,10,15,28,4,4,116,28,17,0,42,26,17,6,22,28,19,6,16,30,2,7,111,28,17,0,46,28,7,16,24,30,34,0,13,24,4,5,121,30,4,14,47,28,11,14,24,30,16,14,15,30,6,4,117,30,6,14,45,28,11,16,24,30,30,2,16,30,8,4,106,26,8,13,47,28,7,22,24,30,22,13,15,30,10,2,114,28,19,4,46,28,28,6,22,28,33,4,16,30,8,4,122,30,22,3,45,28,8,26,23,30,12,28,15,30,3,10,117,30,3,23,45,28,4,31,24,30,11,31,15,30,7,7,116,30,21,7,45,28,1,37,23,30,19,26,15,30,5,10,115,30,19,10,47,28,15,25,24,30,23,25,15,30,13,3,115,30,2,29,46,28,42,1,24,30,23,28,15,30,17,0,115,30,10,23,46,28,10,35,24,30,19,35,15,30,17,1,115,30,14,21,46,28,29,19,24,30,11,46,15,30,13,6,115,30,14,23,46,28,44,7,24,30,59,1,16,30,12,7,121,30,12,26,47,28,39,14,24,30,22,41,15,30,6,14,121,30,6,34,47,28,46,10,24,30,2,64,15,30,17,4,122,30,29,14,46,28,49,10,24,30,24,46,15,30,4,18,122,30,13,32,46,28,48,14,24,30,42,32,15,30,20,4,117,30,40,7,47,28,43,22,24,30,10,67,15,30,19,6,118,30,18,31,47,28,34,34,24,30,20,61,15,30],f=[255,0,1,25,2,50,26,198,3,223,51,238,27,104,199,75,4,100,224,14,52,141,239,129,28,193,105,248,200,8,76,113,5,138,101,47,225,36,15,33,53,147,142,218,240,18,130,69,29,181,194,125,106,39,249,185,201,154,9,120,77,228,114,166,6,191,139,98,102,221,48,253,226,152,37,179,16,145,34,136,54,208,148,206,143,150,219,189,241,210,19,92,131,56,70,64,30,66,182,163,195,72,126,110,107,58,40,84,250,133,186,61,202,94,155,159,10,21,121,43,78,212,229,172,115,243,167,87,7,112,192,247,140,128,99,13,103,74,222,237,49,197,254,24,227,165,153,119,38,184,180,124,17,68,146,217,35,32,137,46,55,63,209,91,149,188,207,205,144,135,151,178,220,252,190,97,242,86,211,171,20,42,93,158,132,60,57,83,71,109,65,162,31,45,67,216,183,123,164,118,196,23,73,236,127,12,111,246,108,161,59,82,41,157,85,170,251,96,134,177,187,204,62,90,203,89,95,176,156,169,160,81,11,245,22,235,122,117,44,215,79,174,213,233,230,231,173,232,116,214,244,234,168,80,88,175],u=[1,2,4,8,16,32,64,128,29,58,116,232,205,135,19,38,76,152,45,90,180,117,234,201,143,3,6,12,24,48,96,192,157,39,78,156,37,74,148,53,106,212,181,119,238,193,159,35,70,140,5,10,20,40,80,160,93,186,105,210,185,111,222,161,95,190,97,194,153,47,94,188,101,202,137,15,30,60,120,240,253,231,211,187,107,214,177,127,254,225,223,163,91,182,113,226,217,175,67,134,17,34,68,136,13,26,52,104,208,189,103,206,129,31,62,124,248,237,199,147,59,118,236,197,151,51,102,204,133,23,46,92,184,109,218,169,79,158,33,66,132,21,42,84,168,77,154,41,82,164,85,170,73,146,57,114,228,213,183,115,230,209,191,99,198,145,63,126,252,229,215,179,123,246,241,255,227,219,171,75,150,49,98,196,149,55,110,220,165,87,174,65,130,25,50,100,200,141,7,14,28,56,112,224,221,167,83,166,81,162,89,178,121,242,249,239,195,155,43,86,172,69,138,9,18,36,72,144,61,122,244,245,247,243,251,235,203,139,11,22,44,88,176,125,250,233,207,131,27,54,108,216,173,71,142,0],x=[],p=[],g=[],v=[],b=[],y=2;function w(t,e){var r;t>e&&(r=t,t=e,e=r),r=e,r*=e,r+=e,r>>=1,v[r+=t]=1}function P(t,e){var r;for(g[t+i*e]=1,r=-2;r<2;r++)g[t+r+i*(e-2)]=1,g[t-2+i*(e+r+1)]=1,g[t+2+i*(e+r)]=1,g[t+r+1+i*(e+2)]=1;for(r=0;r<2;r++)w(t-1,e+r),w(t+1,e-r),w(t-r,e-1),w(t+r,e+1)}function m(t){for(;t>=255;)t=((t-=255)>>8)+(255&t);return t}var _=[];function S(t,e,r,i){var s,o,n;for(s=0;s<i;s++)x[r+s]=0;for(s=0;s<e;s++){if(255!=(n=f[x[t+s]^x[r]]))for(o=1;o<i;o++)x[r+o-1]=x[r+o]^u[m(n+_[i-o])];else for(o=r;o<r+i;o++)x[o]=x[o+1];x[r+i-1]=255==n?0:u[m(n+_[0])]}}function M(t,e){var r;return t>e&&(r=t,t=e,e=r),r=e,r+=e*e,r>>=1,v[r+=t]}function C(t){var e,r,s,o;switch(t){case 0:for(r=0;r<i;r++)for(e=0;e<i;e++)e+r&1||M(e,r)||(g[e+r*i]^=1);break;case 1:for(r=0;r<i;r++)for(e=0;e<i;e++)1&r||M(e,r)||(g[e+r*i]^=1);break;case 2:for(r=0;r<i;r++)for(s=0,e=0;e<i;e++,s++)3==s&&(s=0),s||M(e,r)||(g[e+r*i]^=1);break;case 3:for(o=0,r=0;r<i;r++,o++)for(3==o&&(o=0),s=o,e=0;e<i;e++,s++)3==s&&(s=0),s||M(e,r)||(g[e+r*i]^=1);break;case 4:for(r=0;r<i;r++)for(s=0,o=r>>1&1,e=0;e<i;e++,s++)3==s&&(s=0,o=!o),o||M(e,r)||(g[e+r*i]^=1);break;case 5:for(o=0,r=0;r<i;r++,o++)for(3==o&&(o=0),s=0,e=0;e<i;e++,s++)3==s&&(s=0),(e&r&1)+!(!s|!o)||M(e,r)||(g[e+r*i]^=1);break;case 6:for(o=0,r=0;r<i;r++,o++)for(3==o&&(o=0),s=0,e=0;e<i;e++,s++)3==s&&(s=0),(e&r&1)+(s&&s==o)&1||M(e,r)||(g[e+r*i]^=1);break;case 7:for(o=0,r=0;r<i;r++,o++)for(3==o&&(o=0),s=0,e=0;e<i;e++,s++)3==s&&(s=0),(s&&s==o)+(e+r&1)&1||M(e,r)||(g[e+r*i]^=1)}}function k(t){var e,r=0;for(e=0;e<=t;e++)b[e]>=5&&(r+=3+b[e]-5);for(e=3;e<t-1;e+=2)b[e-2]==b[e+2]&&b[e+2]==b[e-1]&&b[e-1]==b[e+1]&&3*b[e-1]==b[e]&&(0==b[e-3]||e+3>t||3*b[e-3]>=4*b[e]||3*b[e+3]>=4*b[e])&&(r+=40);return r}function R(){var t,e,r,s,o,n=0,c=0;for(e=0;e<i-1;e++)for(t=0;t<i-1;t++)(g[t+i*e]&&g[t+1+i*e]&&g[t+i*(e+1)]&&g[t+1+i*(e+1)]||!(g[t+i*e]||g[t+1+i*e]||g[t+i*(e+1)]||g[t+1+i*(e+1)]))&&(n+=3);for(e=0;e<i;e++){for(b[0]=0,r=s=t=0;t<i;t++)(o=g[t+i*e])==s?b[r]++:b[++r]=1,c+=(s=o)?1:-1;n+=k(r)}c<0&&(c=-c);var a=c,h=0;for(a+=a<<2,a<<=1;a>i*i;)a-=i*i,h++;for(n+=10*h,t=0;t<i;t++){for(b[0]=0,r=s=e=0;e<i;e++)(o=g[t+i*e])==s?b[r]++:b[++r]=1,s=o;n+=k(r)}return n}var I,T=null;e.api={get ecclevel(){return y},set ecclevel(t){y=t},get size(){return I},set size(t){I=t},get canvas(){return T},set canvas(t){T=t},getFrame:function(t){return function(t){var e,b,k,I,T,j,A,O;I=t.length,r=0;do{if(r++,k=4*(y-1)+16*(r-1),s=d[k++],o=d[k++],n=d[k++],c=d[k],I<=(k=n*(s+o)+o-3+(r<=9)))break}while(r<40);for(i=17+4*r,T=n+(n+c)*(s+o)+o,I=0;I<T;I++)p[I]=0;for(x=t.slice(0),I=0;I<i*i;I++)g[I]=0;for(I=0;I<(i*(i+1)+1)/2;I++)v[I]=0;for(I=0;I<3;I++){for(k=0,b=0,1==I&&(k=i-7),2==I&&(b=i-7),g[b+3+i*(k+3)]=1,e=0;e<6;e++)g[b+e+i*k]=1,g[b+i*(k+e+1)]=1,g[b+6+i*(k+e)]=1,g[b+e+1+i*(k+6)]=1;for(e=1;e<5;e++)w(b+e,k+1),w(b+1,k+e+1),w(b+5,k+e),w(b+e+1,k+5);for(e=2;e<4;e++)g[b+e+i*(k+2)]=1,g[b+2+i*(k+e+1)]=1,g[b+4+i*(k+e)]=1,g[b+e+1+i*(k+4)]=1}if(r>1)for(I=a[r],b=i-7;;){for(e=i-7;e>I-3&&(P(e,b),!(e<I));)e-=I;if(b<=I+9)break;P(6,b-=I),P(b,6)}for(g[8+i*(i-8)]=1,b=0;b<7;b++)w(7,b),w(i-8,b),w(7,b+i-7);for(e=0;e<8;e++)w(e,7),w(e+i-8,7),w(e,i-8);for(e=0;e<9;e++)w(e,8);for(e=0;e<8;e++)w(e+i-8,8),w(8,e);for(b=0;b<7;b++)w(8,b+i-7);for(e=0;e<i-14;e++)1&e?(w(8+e,6),w(6,8+e)):(g[8+e+6*i]=1,g[6+i*(8+e)]=1);if(r>6)for(I=h[r-7],k=17,e=0;e<6;e++)for(b=0;b<3;b++,k--)1&(k>11?r>>k-12:I>>k)?(g[5-e+i*(2-b+i-11)]=1,g[2-b+i-11+i*(5-e)]=1):(w(5-e,2-b+i-11),w(2-b+i-11,5-e));for(b=0;b<i;b++)for(e=0;e<=b;e++)g[e+i*b]&&w(e,b);for(T=x.length,j=0;j<T;j++)p[j]=x.charCodeAt(j);if(x=p.slice(0),T>=(e=n*(s+o)+o)-2&&(T=e-2,r>9&&T--),j=T,r>9){for(x[j+2]=0,x[j+3]=0;j--;)I=x[j],x[j+3]|=255&I<<4,x[j+2]=I>>4;x[2]|=255&T<<4,x[1]=T>>4,x[0]=64|T>>12}else{for(x[j+1]=0,x[j+2]=0;j--;)I=x[j],x[j+2]|=255&I<<4,x[j+1]=I>>4;x[1]|=255&T<<4,x[0]=64|T>>4}for(j=T+3-(r<10);j<e;)x[j++]=236,x[j++]=17;for(_[0]=1,j=0;j<c;j++){for(_[j+1]=1,A=j;A>0;A--)_[A]=_[A]?_[A-1]^u[m(f[_[A]]+j)]:_[A-1];_[0]=u[m(f[_[0]]+j)]}for(j=0;j<=c;j++)_[j]=f[_[j]];for(k=e,b=0,j=0;j<s;j++)S(b,n,k,c),b+=n,k+=c;for(j=0;j<o;j++)S(b,n+1,k,c),b+=n+1,k+=c;for(b=0,j=0;j<n;j++){for(A=0;A<s;A++)p[b++]=x[j+A*n];for(A=0;A<o;A++)p[b++]=x[s*n+j+A*(n+1)]}for(A=0;A<o;A++)p[b++]=x[s*n+j+A*(n+1)];for(j=0;j<c;j++)for(A=0;A<s+o;A++)p[b++]=x[e+j+A*c];for(x=p,e=b=i-1,k=T=1,O=(n+c)*(s+o)+o,j=0;j<O;j++)for(I=x[j],A=0;A<8;A++,I<<=1){128&I&&(g[e+i*b]=1);do{T?e--:(e++,k?0!=b?b--:(k=!k,6==(e-=2)&&(e--,b=9)):b!=i-1?b++:(k=!k,6==(e-=2)&&(e--,b-=8))),T=!T}while(M(e,b))}for(x=g.slice(0),I=0,b=3e4,k=0;k<8&&(C(k),(e=R())<b&&(b=e,I=k),7!=I);k++)g=x.slice(0);for(I!=k&&C(I),b=l[I+(y-1<<3)],k=0;k<8;k++,b>>=1)1&b&&(g[i-1-k+8*i]=1,k<6?g[8+i*k]=1:g[8+i*(k+1)]=1);for(k=0;k<7;k++,b>>=1)1&b&&(g[8+i*(i-7+k)]=1,k?g[6-k+8*i]=1:g[7+8*i]=1);return g}(t)},utf16to8:function(t){var e,r,i,s;for(e="",i=t.length,r=0;r<i;r++)(s=t.charCodeAt(r))>=1&&s<=127?e+=t.charAt(r):s>2047?(e+=String.fromCharCode(224|s>>12&15),e+=String.fromCharCode(128|s>>6&63),e+=String.fromCharCode(128|s>>0&63)):(e+=String.fromCharCode(192|s>>6&31),e+=String.fromCharCode(128|s>>0&63));return e},draw:function(t,e,r,s,o,n,c,a,h,l){if(y=l||y,e){var d=Math.min(o,n);t=this.utf16to8(t);var f=this.getFrame(t),u=d/i;c&&(e.fillStyle=c,e.fillRect(r,s,o,o)),e.fillStyle=a||"black";for(var x=0;x<i;x++)for(var p=0;p<i;p++)f[p*i+x]&&e.fillRect(r+u*x,s+u*p,u,u)}else console.warn("No canvas provided to draw QR code in!")}}},593:function(t,e,r){var i=this&&this.__assign||function(){return(i=Object.assign||function(t){for(var e,r=1,i=arguments.length;r<i;r++)for(var s in e=arguments[r])Object.prototype.hasOwnProperty.call(e,s)&&(t[s]=e[s]);return t}).apply(this,arguments)},s=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0}),e.initInjection=e.injection=e.setStringPrototype=e.toPx=void 0;var o=s(r(563)),n=r(779),c=.5,a=1,h=function(t,e){void 0===e&&(e=100);var r=/-?[0-9]+(\.[0-9]+)?(rpx|px|%)/.exec(t);if(!t||!r)return console.error("The size: "+t+" is illegal"),"0";var i=r[2],s=parseFloat(t),o=0;return"rpx"===i?o=Math.round(s*(c||.5)*(a||1)):"px"===i?o=Math.round(s*(a||1)):"%"===i&&(o=Math.round(s*e/100)),String(o)};e.toPx=function(t,e){if("number"==typeof t)return t;if("0"===t)return 0;var r=/^calc\((.+)\)$/.exec(t);if(r&&r[1]){var i=r[1].replace(/([^\s\(\+\-\*\/]+)\.(left|right|bottom|top|width|height)/g,(function(t){var e=t.split("."),r=e[0],i=e[1];return n.penCache.viewRect[r]?n.penCache.viewRect[r][i]:0})).replace(/-?[0-9]+(\.[0-9]+)?(rpx|px|%)/g,(function(t){return h(t,e)}));return o.default(i)}return Number(h(t,e))},e.setStringPrototype=function(t,e){void 0===t&&(t=.5),void 0===e&&(e=1),c=t,a=e},e.injection={loadImage:function(t){return Promise.resolve({img:t,width:0,height:0})},getRatio:function(){return 1},customActions:{}},e.initInjection=function(t){e.injection=i(i({},e.injection),t)}}},r={};function i(t){var s=r[t];if(void 0!==s)return s.exports;var o=r[t]={exports:{}};return e[t].call(o.exports,o,o.exports,i),o.exports}var s={};(()=>{var t=s;Object.defineProperty(t,"X$",{value:!0}),t.Gm=t.BM=t.y1=t.I8=t.aR=t.C5=void 0;var e=i(593);Object.defineProperty(t,"C5",{enumerable:!0,get:function(){return e.setStringPrototype}}),Object.defineProperty(t,"aR",{enumerable:!0,get:function(){return e.toPx}}),Object.defineProperty(t,"I8",{enumerable:!0,get:function(){return e.initInjection}});var r=i(779);Object.defineProperty(t,"y1",{enumerable:!0,get:function(){return r.penCache}}),Object.defineProperty(t,"BM",{enumerable:!0,get:function(){return r.clearPenCache}}),Object.defineProperty(t,"Gm",{enumerable:!0,get:function(){return r.Pen}})})();var o=s.Gm,n=s.BM,c=s.I8,a=s.y1,h=s.C5,l=s.aR;return class{constructor(e,r={injection:{},screenK:1,scale:1}){this.ctx=e,c(Object.assign({loadImage:e=>t(this,void 0,void 0,(function*(){return new Promise((t=>{const r=new Image;r.onload=function(){t({img:r,height:r.height,width:r.width})},r.src=e}))}))},r.injection)),h(r.screenK,r.scale)}clearPenCache(){n()}getPenCache(){return a}static toPx(t,e){return l(t,e)}paint(t,e){new o(this.ctx,t).paint(e)}}}));