UNPKG

draw-html-to-canvas

Version:

根据html+css规范绘制 网页到canvas

1 lines 61.2 kB
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).DrawHtml2Canvas={})}(this,(function(t){"use strict";var e=function(t,i){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i])},e(t,i)};function i(t,i){if("function"!=typeof i&&null!==i)throw new TypeError("Class extends value "+String(i)+" is not a constructor or null");function o(){this.constructor=t}e(t,i),t.prototype=null===i?Object.create(i):(o.prototype=i.prototype,new o)}var o,n=function(){return n=Object.assign||function(t){for(var e,i=1,o=arguments.length;i<o;i++)for(var n in e=arguments[i])Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t},n.apply(this,arguments)};function r(t,e,i){if(i||2===arguments.length)for(var o,n=0,r=e.length;n<r;n++)!o&&n in e||(o||(o=Array.prototype.slice.call(e,0,n)),o[n]=e[n]);return t.concat(o||Array.prototype.slice.call(e))}!function(t){t.image="image",t.gradient="gradient"}(o||(o={}));var h,l,s,a,c=function(t,e,i,n,r,h,l,s,a,c,d,f,p){t.save(),t.translate(s,a),t.beginPath(),t.rect(0,0,c,d),t.clip();var g=-Math.ceil(h/n)*n+h,u=-Math.ceil(l/r)*r+l,y=Math.ceil(d/r)+1,w=Math.ceil(c/n)+1,b=!1;if(e===o.gradient&&(t.fillStyle=i,b=!0),f===at.repeat){b&&t.translate(g,u);for(var m=0;m<y;m++){for(var v=0;v<w;v++){var T=v*n,x=m*r;e===o.image?t.drawImage(i,g+T,u+x,n,r):e===o.gradient&&(t.fillRect(0,0,n,r),t.translate(n,0))}b&&t.translate(-w*n,r)}}else if(f===at.repeatY){b&&t.translate(h,u);for(m=0;m<y;m++){x=m*r;e===o.image?t.drawImage(i,h,x+u,n,r):e===o.gradient&&(t.fillRect(0,0,n,r),t.translate(0,r))}}else if(f===at.repeatX){b&&t.translate(g,l);for(v=0;v<w;v++){T=v*n;e===o.image?t.drawImage(i,T+g,l,n,r):e===o.gradient&&(t.fillRect(0,0,n,r),t.translate(n,0))}}else f===at.noRepeat&&(e===o.image?t.drawImage(i,h,l,n,r):e===o.gradient&&(t.translate(h,l),t.fillRect(0,0,n,r)));"function"==typeof p&&p(t),t.restore()},d=function(t){return Object.values?Object.values(t):Object.keys(t).map((function(e){return t[e]}))},f=function(t,e,i,o,n){var r=(1-n)*t+e*n,h=(1-n)*e+i*n,l=(1-n)*r+h*n;return[t,r,l,(1-n)*l+((1-n)*h+((1-n)*i+o*n)*n)*n]},p=function(t,e,i,o,n){var r=(1-n)*e+i*n,h=(1-n)*i+o*n,l=(1-n)*r+h*n;return[(1-n)*((1-n)*((1-n)*t+e*n)+r*n)+l*n,l,h,o]},g=function(t,e,i,o,n,r){var h=f(t,e,i,o,r),l=h[0],s=h[1],a=h[2],c=h[3];return p(l,s,a,c,n/r)},u=function(t,e,i,o,n,h,l,s,a){if(t.ellipse)return t.ellipse(e,i,o,n,h,l,s,a);var c=Math.PI/180,d=l/c,u=s/c;if(0!==o&&0!==n&&d!==u){var y=.5522848,w=o*y,b=n*y,m=e+o,v=i+n;if(t.save(),t.translate(e,i),t.rotate(h),t.translate(-e,-i),d<0){var T=Math.abs(d),x=T%360,O=Math.ceil(T/360);if(d=360*O-x,u<0){var E=(P=Math.abs(u))%360;(u=360*(k=Math.ceil(P/360))-E)<d&&(u+=360*O)}else u+=360*O}else if(u<0){var P,k;E=(P=Math.abs(u))%360;u=360*(k=Math.ceil(P/360))-E,d+=360*(k-1)}for(var N=[[[m,i],[m,i+b],[e+w,v],[e,v]],[[e,v],[e-w,v],[e-o,i+b],[e-o,i]],[[e-o,i],[e-o,i-b],[e-w,i-n],[e,i-n]],[[e,i-n],[e+w,i-n],[m,i-b],[m,i]]],W=0,L=[];d+W<u;){var M=d+W,H=Math.floor(M/90)%4;L.push(N[H]),W+=0===W&&d%90!=0?90-d%90:90}L.length&&(1===L.length&&d%90!=0&&u%90!=0?L[0]=function(t,e,i){var o=t[0],n=t[1],r=t[2],h=t[3],l=g(o[0],n[0],r[0],h[0],e,i),s=g(o[1],n[1],r[1],h[1],e,i);return[[l[0],s[0]],[l[1],s[1]],[l[2],s[2]],[l[3],s[3]]]}(L[0],d%90/90,u%90/90):(d%90!=0&&(L[0]=function(t,e){var i=t[0],o=t[1],n=t[2],r=t[3],h=p(i[0],o[0],n[0],r[0],e),l=p(i[1],o[1],n[1],r[1],e);return[[h[0],l[0]],[h[1],l[1]],[h[2],l[2]],[h[3],l[3]]]}(L[0],d%90/90)),u%90!=0&&(L[L.length-1]=function(t,e){var i=t[0],o=t[1],n=t[2],r=t[3],h=f(i[0],o[0],n[0],r[0],e),l=f(i[1],o[1],n[1],r[1],e);return[[h[0],l[0]],[h[1],l[1]],[h[2],l[2]],[h[3],l[3]]]}(L[L.length-1],u%90/90))),L.forEach((function(e,i){var o=e[0],n=e[1],h=e[2],l=e[3];0===i&&t.lineTo.apply(t,o),t.bezierCurveTo.apply(t,r(r(r([],n,!1),h,!1),l,!1))}))),t.restore()}},y=function(t){return Object.keys(t).forEach((function(e){var i=e;/-/.test(i)&&(i=i.split("-").map((function(t,e){return e>0?t[0].toUpperCase()+t.slice(1):t})).join(""),delete t[e]),t[i]=e})),t},w=y({inherit:"",initial:"",auto:"",color:"",font:"",style:"",variant:"",weight:"",stretch:"",family:"",top:"",right:"",bottom:"",left:"",size:"",line:"",text:"",decoration:"",none:"",background:"",image:"",position:"",repeat:"",clip:"",origin:"",width:"",height:"",padding:"",margin:"",border:"",radius:"",display:"",absolute:"",relative:"",float:"",align:"",center:"",clear:"",overflow:"",hidden:"",visible:"",opacity:"",thickness:"",nowrap:"",shadow:"",box:""}),b=y(n(n({},w),((h={"vertical-align":"","white-space":"","z-index":""})["".concat(w.font,"-").concat(w.style)]="",h["".concat(w.font,"-").concat(w.variant)]="",h["".concat(w.font,"-").concat(w.weight)]="",h["".concat(w.font,"-").concat(w.stretch)]="",h["".concat(w.font,"-").concat(w.size)]="",h["".concat(w.font,"-").concat(w.family)]="",h["".concat(w.line,"-").concat(w.height)]="",h["".concat(w.text,"-").concat(w.decoration)]="",h["".concat(w.text,"-").concat(w.decoration,"-").concat(w.color)]="",h["".concat(w.text,"-").concat(w.decoration,"-").concat(w.style)]="",h["".concat(w.text,"-").concat(w.decoration,"-").concat(w.thickness)]="",h["".concat(w.text,"-").concat(w.decoration,"-").concat(w.line)]="",h["".concat(w.background,"-").concat(w.image)]="",h["".concat(w.background,"-").concat(w.color)]="",h["".concat(w.background,"-").concat(w.position)]="",h["".concat(w.background,"-").concat(w.size)]="",h["".concat(w.background,"-").concat(w.repeat)]="",h["".concat(w.background,"-").concat(w.clip)]="",h["".concat(w.background,"-").concat(w.origin)]="",h["".concat(w.border,"-").concat(w.top)]="",h["".concat(w.border,"-").concat(w.right)]="",h["".concat(w.border,"-").concat(w.bottom)]="",h["".concat(w.border,"-").concat(w.left)]="",h["".concat(w.border,"-").concat(w.top,"-").concat(w.width)]="",h["".concat(w.border,"-").concat(w.right,"-").concat(w.width)]="",h["".concat(w.border,"-").concat(w.bottom,"-").concat(w.width)]="",h["".concat(w.border,"-").concat(w.left,"-").concat(w.width)]="",h["".concat(w.border,"-").concat(w.top,"-").concat(w.style)]="",h["".concat(w.border,"-").concat(w.right,"-").concat(w.style)]="",h["".concat(w.border,"-").concat(w.bottom,"-").concat(w.style)]="",h["".concat(w.border,"-").concat(w.left,"-").concat(w.style)]="",h["".concat(w.border,"-").concat(w.top,"-").concat(w.color)]="",h["".concat(w.border,"-").concat(w.right,"-").concat(w.color)]="",h["".concat(w.border,"-").concat(w.bottom,"-").concat(w.color)]="",h["".concat(w.border,"-").concat(w.left,"-").concat(w.color)]="",h["".concat(w.border,"-").concat(w.radius)]="",h["".concat(w.border,"-").concat(w.top,"-").concat(w.left,"-").concat(w.radius)]="",h["".concat(w.border,"-").concat(w.top,"-").concat(w.right,"-").concat(w.radius)]="",h["".concat(w.border,"-").concat(w.bottom,"-").concat(w.right,"-").concat(w.radius)]="",h["".concat(w.border,"-").concat(w.bottom,"-").concat(w.left,"-").concat(w.radius)]="",h["".concat(w.text,"-").concat(w.shadow)]="",h["".concat(w.box,"-").concat(w.shadow)]="",h))),m=b.top;!function(t){t[t.ELEMENT_NODE=1]="ELEMENT_NODE",t[t.TEXT_NODE=3]="TEXT_NODE",t[t.CDATA_SECTION_NODE=4]="CDATA_SECTION_NODE",t[t.PROCESSING_INSTRUCTION_NODE=7]="PROCESSING_INSTRUCTION_NODE",t[t.COMMENT_NODE=8]="COMMENT_NODE",t[t.DOCUMENT_NODE=9]="DOCUMENT_NODE",t[t.DOCUMENT_TYPE_NODE=10]="DOCUMENT_TYPE_NODE",t[t.DOCUMENT_FRAGMENT_NODE=11]="DOCUMENT_FRAGMENT_NODE"}(l||(l={})),function(t){t.block="block",t.inline="inline",t.inlineBlock="inline-block",t.flex="flex",t.none="none"}(s||(s={})),function(t){t.div="div",t.img="img",t.br="br",t.hr="hr",t.span="span"}(a||(a={}));var v,T="rgba\\(\\s*(?:\\d{1,3}\\s*,\\s*){3}\\s*(?:\\d|\\.\\d+|\\d\\.\\d+)\\s*\\)|rgb\\(\\s*(?:\\d{1,3}\\s*,\\s*){2}\\s*\\d{1,3}\\s*\\)|(?:#[a-z0-9]{6})|(?:#[a-z0-9]{3})|transparent|currentColor",x=new RegExp(T,"i"),O=/px$/i,E=/%$/,P=/rem$/i,k=/em$/i,N=/^\d+(?:.\d+)?$/,W=/url\((?:'([^']+)'|("[^"]+")|([^)]+))\)/i,L=/repeat-y|repeat-x|no-repeat|repeat/i,M=/scroll|fixed|local/i,H=/border-box|padding-box|content-box/gi,I="(?:-?\\d*(?:\\.\\d+)?)(?:%|px)?",R="(?:\\d*(?:\\.\\d+)?)(?:%|px)?",S="(".concat(I,")"),j="left|center|right|top|bottom",_="(".concat(j,")"),D="(?:(".concat(j,")\\s+").concat(S,"?)"),U="(auto|".concat(I,")"),B="(?:".concat("(cover|contain)","|(?:").concat(U,"(?:\\s+").concat(U,")?))"),C=new RegExp(j,"i"),z=/left|right/,F=/top|bottom/,A=new RegExp("(?:".concat(_,"\\s+").concat(S,"\\s+").concat(_,"\\s+").concat(S,")|(?:").concat(_,"\\s+((?:").concat(j,")|").concat(I,")\\s+((?:").concat(j,")|").concat(I,"))|(?:(?:").concat(_,"|").concat(S,")\\s+(?:").concat(_,"|").concat(S,"))|(?:").concat(_,"|").concat(S,")"),"i"),X=new RegExp(B,"i"),Y=new RegExp("\\s*(".concat(D,"|").concat(S,")(?:\\s*(").concat(D,"|").concat(S,"))?(?:\\s*\\/\\s*").concat(B,")"),"i"),G=function(t){return"((?:(".concat(t,")\\s+(").concat(t,")\\s+(").concat(t,")\\s+(").concat(t,"))|(?:(").concat(t,")\\s+(").concat(t,")\\s+(").concat(t,"))|(?:(").concat(t,")\\s+(").concat(t,"))|(").concat(t,"))")},V=new RegExp(G("auto|".concat(I)),"i"),$=G(R),q=new RegExp("(?:".concat($,"(?:\\s*/\\s*").concat($,")?)"),"i"),J=new RegExp("(".concat(R,")(?:\\s+(").concat(R,"))?"),"i");!function(t){t.none="none",t.hidden="hidden",t.dotted="dotted",t.dashed="dashed",t.solid="solid",t.double="double",t.ridge="ridge",t.inset="inset",t.outset="outset"}(v||(v={}));var K,Q,Z="(".concat(d(v).join("|"),")"),tt="((?:thin|medium|thick)|(?:".concat(R,"))"),et=new RegExp(tt,"i"),it=new RegExp(Z,"i"),ot=x,nt=new RegExp("".concat(tt,"\\s+").concat(Z,"\\s+(").concat(T,")"),"i"),rt=new RegExp("(?:\\s*,\\s*)?(?:"+["(".concat(T,")\\s+(").concat(I,")\\s+(").concat(I,")\\s+(").concat(I,")"),"(".concat(I,")\\s+(").concat(I,")\\s+(").concat(I,")\\s+(").concat(T,")"),"(".concat(T,")\\s+(").concat(I,")\\s+(").concat(I,")"),"(".concat(I,")\\s+(").concat(I,")\\s+(").concat(T,")"),"(".concat(I,")\\s+(").concat(I,")")].join("|")+")(?:\\s*,\\s*)?","ig");!function(t){t.none="none",t.underline="underline",t.overline="overline",t.lineThrough="line-through"}(K||(K={})),function(t){t.solid="solid",t.double="double",t.dotted="dotted",t.dashed="dashed",t.wavy="wavy"}(Q||(Q={}));var ht,lt,st,at,ct,dt,ft,pt=new RegExp("".concat(d(Q).join("|")),"i"),gt=new RegExp("".concat(d(K).join("|")),"ig"),ut=x,yt=new RegExp(R.slice(0,-1),"i"),wt=/((?:repeating-)?(?:linear|radial)-gradient)/i,bt=/((?:repeating-)?(?:linear|radial)-gradient)\s*\(\s*((?:to\s+(top|bottom)\s+(left|right)|to\s+(left|right)\s+(top|bottom)|to\s+(top|bottom)|to\s+(left|right)|(-?\d+(?:\.?\d+)?(?:deg)?)))?/i,mt=new RegExp("(".concat(T,")(\\s+").concat(I,")?"),"gi"),vt=/([^\s]+)\s*=\s*('([^']+)'|"([^"]+)"|([^=<>"']))?/gi,Tt=/\s*([^:]+)\s*:\s*([^;]+)\s*;?/gi,xt=/br|hr|area|base|img|input|link|meta|basefont|param|col|frame|embed|keygen|source/gi,Ot="#__URL__#",Et=new RegExp(Ot,"g");!function(t){t.repeatingLinearGradient="repeating-linear-gradient",t.repeatingRadialGradient="repeating-radial-gradient",t.linearGradient="linear-gradient",t.radialGradient="radial-gradient"}(ht||(ht={})),function(t){t.left="left",t.center="center",t.right="right",t.top="top",t.bottom="bottom"}(lt||(lt={})),function(t){t.auto="auto",t.cover="cover",t.contain="contain"}(st||(st={})),function(t){t.repeat="repeat",t.noRepeat="no-repeat",t.repeatX="repeat-x",t.repeatY="repeat-y"}(at||(at={})),function(t){t.borderBox="border-box",t.paddingBox="padding-box",t.contentBox="content-box"}(ct||(ct={})),function(t){t.scroll="scroll",t.fixed="fixed",t.local="local"}(dt||(dt={})),function(t){t.left="left",t.center="center",t.right="right"}(ft||(ft={}));var Pt=function(){function t(t){var e=this;this.style={},this.styleIndex={},this.index=0,this.cachedValue={},this.imageMap={},this.updateCache=function(){},this.getImage=function(t){return e.imageMap[t]},this.element=t}return t.prototype.getInheritStyle=function(t,e){void 0===e&&(e=!1);var i=this.getInheritNode(t,e),o=i.element,n=i.value;return o?n:null},t.prototype.getInheritNode=function(t,e){void 0===e&&(e=!1);for(var i=this.element;i;){var o=i.style.get(t);if(o&&o!==b.inherit)return{element:i,value:o};if(!e&&i&&(i.style.isAbsolute||i.style.isFloat))break;i=i.parentNode}return{element:null,value:""}},t.prototype.getOriginRoundStyle=function(t){var e=this,i=this.style[t],o=this.styleIndex[t]||0,n={top:"",right:"",bottom:"",left:""};return"".concat(i).replace(V,(function(t){for(var e=[],i=1;i<arguments.length;i++)e[i-1]=arguments[i];var o=e[1],r=e[2],h=e[3],l=e[4],s=e[5],a=e[6],c=e[7],d=e[8],f=e[9],p=e[10];return o?(n.top=o,n.right=r,n.bottom=h,n.left=l):s?(n.top=s,n.right=a,n.bottom=c,n.left=a):d?(n.top=d,n.right=f,n.bottom=d,n.left=f):p&&(n.top=p,n.right=p,n.bottom=p,n.left=p),""})),Object.keys(n).forEach((function(i){var r="".concat(t,"-").concat(i);(e.styleIndex[r]||0)>o&&(n[i]=e.style[r])})),n},t.prototype.getRoundStyle=function(t){var e=this,i=[b.top,b.right,b.bottom,b.left],o=this.getOriginRoundStyle(t);return i.forEach((function(t){o[t]===b.auto?o[t]=0:o[t]=e.transformUnitToPx(o[t])})),o},t.prototype.get=function(t){return this.style[t]},t.prototype.getNumber=function(t){return this.transformUnitToPx(this.get(t))},t.prototype.set=function(t,e){return this.style[t]=e,this.styleIndex[t]=++this.index,this.updateCache(),this},t.prototype.transformUnitToPx=function(t,e){if(!t||"0"===t)return 0;if(O.test(t))return parseFloat(t);if(!e)throw new Error("missing unit [".concat(t,"]"));return E.test(t)?e*parseFloat(t)/100:P.test(t)||k.test(t)?e*parseFloat(t):parseFloat(t)},Object.defineProperty(t.prototype,"canvasFont",{get:function(){var t=this.getInheritStyle(b.fontStyle,!0),e=this.getInheritStyle(b.fontVariant,!0),i=this.getInheritStyle(b.fontWeight,!0),o=this.getInheritStyle(b.fontStretch,!0),n=this.fontSize,r=this.getInheritStyle(b.fontFamily,!0)||"sans-serif";return[t,e,i,o,"".concat(n,"px"),r].filter((function(t){return t})).join(" ")},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"fontSize",{get:function(){var t=this.getInheritStyle(b.fontSize,!0)||"16px";return parseInt(t)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"textDecoration",{get:function(){var t=this,e=this.getInheritStyle(b.textDecoration),i=[],o="#000",n="",r=1,h=!1;return"".concat(e).replace(ut,(function(t){return o=t,""})).replace(pt,(function(t){return n=t,""})).replace(yt,(function(e){return r=t.transformUnitToPx(e),""})).replace(gt,(function(t){return t===b.none?h=!0:i.push({color:o,style:n,line:t,thickness:r}),""})),h?[]:i},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"background",{get:function(){var t=this,e=this.element;if(e.nodeType===l.TEXT_NODE&&(e=e.parentNode)&&e.blockType!==s.inline)return[];if(!e)return[];var i=function(t){var e=t.split(wt),i=[];return e.reduce((function(t,e){return wt.test(e)?t.push(e):t.length&&(t[t.length-1]+=e),t}),[]).forEach((function(e){var o,n=[],r=0,h=/\(|\)/g;do{if(!(o=h.exec(e)))throw new Error("gradient error [".concat(e,"]"));if("("===o[0])n.push(o[0]);else if(n.pop(),0===n.length){r=o.index;break}}while(o);var l=e.slice(0,r+1),s={};return l.replace(bt,(function(t){for(var e=[],i=1;i<arguments.length;i++)e[i-1]=arguments[i];var o=e[0],n=e[1],r=e[2],h=e[3],l=e[4],a=e[5],c=e[6],d=e[7],f=e[8];return n?r||l?(l&&(r=a,h=l),f=r===b.top?h===b.left?-45:45:h===b.left?225:-225):c?f=c===b.top?0:180:d?f=d===b.left?270:90:f&&(f=parseFloat(f)):f=180,s={type:o,angle:f,list:[]},""})).replace(mt,(function(t,e,i){return s.list.push({color:e,stop:i}),""})),t=t.replace(l,""),i.push(s),l})),{restStyle:t,gradients:i}},o=e.style.style[b.background],n=e.style.styleIndex[b.background]||0,r=[],h=[];if(wt.test(o)){var a=i(o);h=a.gradients,o=a.restStyle}var c="".concat(o||"").replace(x,(function(t){return r.push(t),""})).split(",");r.length>1&&(c=[]);var d=c.map((function(t,e){var i="",o="",n={left:lt.left,leftOffset:"",top:lt.top,topOffset:""},l={width:st.auto,height:st.auto},s=at.repeat,a=ct.borderBox,d="",f=dt.scroll,p=h[e];return e===c.length-1&&(i=r[0]),t.replace(W,(function(t,e,i,n){if(p)throw new Error("渐变和背景图不能一起使用");return o=e||i||n,""})).replace(L,(function(t){return s=t,""})).replace(H,(function(t){return a=d?t:d=t,""})).replace(M,(function(t){return f=t,""})).replace(Y,(function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var i=t[1],o=t[2],r=t[3],h=t[4],s=t[5],a=t[6],c=t[7],d=t[8],f=t[9],p=t[10],g=t[11];return r&&!s&&(c=r,r=""),i&&(n.left=o||h,h&&(n.leftOffset=n.left,n.left=lt.left)),r&&(n.leftOffset=r),s?(n.top=a||d,d&&(n.topOffset=n.top,n.top=lt.top)):o&&o===lt.center&&(n.top=lt.center),c&&(n.topOffset=c),f?l.height=l.width=f:(p&&(l.width=p),g&&(l.height=g)),""})),d=d||ct.paddingBox,{color:i,image:o,gradient:p,position:n,size:l,repeat:s,attachment:f,origin:d,clip:a}})),f=function(){return{color:"",image:"",position:{left:lt.left,leftOffset:"",top:lt.top,topOffset:""},size:{width:st.auto,height:st.auto},repeat:at.repeat,clip:ct.borderBox,origin:ct.paddingBox,attachment:dt.scroll}},p=this.style[b.backgroundImage],g=this.styleIndex[b.backgroundImage]||0,u=this.style[b.backgroundColor],y=this.styleIndex[b.backgroundColor]||0,w=this.style[b.backgroundPosition],m=this.styleIndex[b.backgroundPosition]||0,v=this.style[b.backgroundSize],T=this.styleIndex[b.backgroundSize]||0,O=this.style[b.backgroundRepeat],E=this.styleIndex[b.backgroundRepeat]||0,P=this.style[b.backgroundClip],k=this.styleIndex[b.backgroundClip]||0,N=this.style[b.backgroundOrigin],I=this.styleIndex[b.backgroundOrigin]||0;(m>n&&w.split(",").forEach((function(e,i){e.trim().replace(A,(function(e){for(var o=[],n=1;n<arguments.length;n++)o[n-1]=arguments[n];var r=o[0],h=o[1],l=o[2],s=o[3],a=o[4],c=o[5],p=o[6],g=o[7],u=o[8],y=o[9],w=o[10],m=o[11],v=o[12];d[i]||d.push(f());var T=d[i].position;return r?(T.left=r,T.leftOffset=h,T.top=l,T.topOffset=s):a?z.test(a)||a===b.center?(T.left=a,C.test(c)?(T.leftOffset="",T.top=c,C.test(p)?console.warn("语法错误 background-position: ".concat(t.style[b.backgroundPosition]),t.element):T.topOffset=p):(T.leftOffset=c,F.test(p)?(T.top=p,T.topOffset=""):console.warn("语法错误 background-position: ".concat(t.style[b.backgroundPosition]),t.element))):F.test(a)&&(T.top=a,C.test(c)?(T.topOffset="",T.left=c,C.test(p)?console.warn("语法错误 background-position: ".concat(t.style[b.backgroundPosition]),t.element):T.leftOffset=p):(T.topOffset=c,C.test(p)?(T.top=p,T.topOffset=""):console.warn("语法错误 background-position: ".concat(t.style[b.backgroundPosition]),t.element))):g||u||y||w?g&&y?(z.test(g)?(T.left=g,T.top=y):(T.left=y,T.top=g),T.leftOffset="",T.topOffset=""):u&&w?(T.left=b.left,T.top=b.top,T.leftOffset=u,T.topOffset=w):g&&w?z.test(g)?(T.left=g,T.leftOffset="",T.top=b.top,T.topOffset=w):(T.top=g,T.topOffset="",T.left=b.left,T.leftOffset=w):u&&y&&(F.test(y)?(T.left=b.left,T.leftOffset=u,T.top=y,T.topOffset=""):console.warn("背景位置无效 不允许出现 [10px left|right] 格式",t.element)):(m||v)&&(m?z.test(m)?(T.left=m,T.leftOffset="",T.top=b.top,T.topOffset="50%"):F.test(m)?(T.left=b.left,T.leftOffset="50%",T.top=m,T.topOffset=""):(T.left=b.center,T.leftOffset="",T.top=b.center,T.topOffset=""):(T.left=b.left,T.leftOffset=v,T.top=b.top,T.topOffset="50%")),""}))})),T>n&&v.split(",").forEach((function(t,e){t.trim().replace(X,(function(t){for(var i=[],o=1;o<arguments.length;o++)i[o-1]=arguments[o];var n=i[0],r=i[1],h=i[2];d[e]||d.push(f());var l=d[e].size;return n?l.width=n:(r&&(l.width=r),l.height=h||b.auto),""}))})),g>n)&&(wt.test(p)?(a=i(p)).gradients.forEach((function(t,e){d[e]||d.push(f()),d[e].gradient=t})):p.split(",").forEach((function(t,e){t.replace(W,(function(t,i,o,n){return d[e]||d.push(f()),d[e].image=i||o||n,""}))})));return E>n&&O.split(",").forEach((function(t,e){t.replace(L,(function(t){return d[e]||d.push(f()),d[e].repeat=t,""}))})),k>n&&P.split(",").forEach((function(t,e){t.replace(H,(function(t){return d[e]||d.push(f()),d[e].clip=t,""}))})),I>n&&N.split(",").forEach((function(t,e){t.replace(H,(function(t){return d[e]||d.push(f()),d[e].origin=t,""}))})),y>n&&x.test(u)&&(0===d.length&&d.push(f()),d[d.length-1].color=u),d.filter((function(t){return t.color||t.image||t.gradient}))},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"width",{get:function(){return this.style[b.width]},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"height",{get:function(){return this.style[b.height]},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"padding",{get:function(){var t=this.element;if(t.nodeType===l.TEXT_NODE){if((t=t.parentNode)&&t.blockType===s.inline){var e=t.style.padding;return e.left=e.right=0,e}return{top:0,right:0,bottom:0,left:0}}return this.getRoundStyle(b.padding)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"margin",{get:function(){return this.getRoundStyle(b.margin)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"border",{get:function(){var t=this,e=this.element;if(e.nodeType===l.TEXT_NODE)return(e=e.parentNode)&&e.blockType===s.inline?e.style.border:{top:{width:0,style:v.none,color:"",image:""},right:{width:0,style:v.none,color:"",image:""},bottom:{width:0,style:v.none,color:"",image:""},left:{width:0,style:v.none,color:"",image:""}};var i=function(e){var i={width:0,style:"",color:"",image:""};return"".concat(e||"").replace(nt,(function(e,o,n,r){return i.width=t.transformUnitToPx(o),i.style=n,i.color=r,""})),i},o=function(e){return et.test(e)?t.transformUnitToPx(e):0},r=function(t){return it.test(t)?t:""},h=function(t){return ot.test(t)?t:""},a=i(this.style[b.border]),c=this.styleIndex[b.border]||0,d=n({},a),f=n({},a),p=n({},a),g=n({},a),u=[this.style[b.borderTop]?i(this.style[b.borderTop]):d,this.style[b.borderRight]?i(this.style[b.borderRight]):f,this.style[b.borderBottom]?i(this.style[b.borderBottom]):p,this.style[b.borderLeft]?i(this.style[b.borderLeft]):g],y=[this.styleIndex[b.borderTop]||0,this.styleIndex[b.borderRight]||0,this.styleIndex[b.borderBottom]||0,this.styleIndex[b.borderLeft]||0],w=[o(this.style[b.borderTopWidth]),o(this.style[b.borderRightWidth]),o(this.style[b.borderBottomWidth]),o(this.style[b.borderLeftWidth])];[this.styleIndex[b.borderTopWidth]||0,this.styleIndex[b.borderRightWidth]||0,this.styleIndex[b.borderBottomWidth]||0,this.styleIndex[b.borderLeftWidth]||0].forEach((function(t,e){t>y[e]&&(u[e].width=w[e])}));var m=[r(this.style[b.borderTopStyle]),r(this.style[b.borderRightStyle]),r(this.style[b.borderBottomStyle]),r(this.style[b.borderLeftStyle])];[this.styleIndex[b.borderTopStyle]||0,this.styleIndex[b.borderRightStyle]||0,this.styleIndex[b.borderBottomStyle]||0,this.styleIndex[b.borderLeftStyle]||0].forEach((function(t,e){t>y[e]&&(u[e].style=m[e])}));var T=[h(this.style[b.borderTopColor]),h(this.style[b.borderRightColor]),h(this.style[b.borderBottomColor]),h(this.style[b.borderLeftColor])];return[this.styleIndex[b.borderTopColor]||0,this.styleIndex[b.borderRightColor]||0,this.styleIndex[b.borderBottomColor]||0,this.styleIndex[b.borderLeftColor]||0].forEach((function(t,e){t>y[e]&&(u[e].color=T[e])})),y[0]>c&&(d=u[0]),y[1]>c&&(f=u[1]),y[2]>c&&(p=u[2]),y[3]>c&&(g=u[3]),{top:d,right:f,bottom:p,left:g}},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"radius",{get:function(){var t=this,e=this.element;if(e.nodeType===l.TEXT_NODE)return(e=e.parentNode)&&e.blockType===s.inline?e.style.radius:{topLeft:{width:0,height:0},topRight:{width:0,height:0},bottomRight:{width:0,height:0},bottomLeft:{width:0,height:0}};var i={width:0,height:0},o={width:0,height:0},n={width:0,height:0},r={width:0,height:0},h=this.style[b.borderRadius],a=this.styleIndex[b.borderRadius]||0;h&&h.replace(q,(function(t){for(var e=[],h=1;h<arguments.length;h++)e[h-1]=arguments[h];e[0];var l=e[1],s=e[2],a=e[3],c=e[4],d=e[5],f=e[6],p=e[7],g=e[8],u=e[9],y=e[10],w=e[11],b=e[12],m=e[13],v=e[14],T=e[15],x=e[16],O=e[17],E=e[18],P=e[19],k=e[20],N=e[21];return l?(i.width=i.height=l,o.width=o.height=s,n.width=n.height=a,r.width=r.height=c):d?(i.width=i.height=l,r.width=r.height=o.width=o.height=f,n.width=n.height=p):g?(i.width=i.height=n.width=n.height=g,r.width=r.height=o.width=o.height=u):y&&(i.width=i.height=o.width=o.height=n.width=n.height=r.width=r.height=y),w&&(b?(i.height=b,o.height=m,n.height=v,r.height=T):x?(i.height=x,r.height=o.height=O,n.height=E):P?(i.height=n.height=P,r.height=o.height=k):N&&(i.height=o.height=n.height=r.height=N)),""})),[{target:i,key:b.borderTopLeftRadius},{target:o,key:b.borderTopRightRadius},{target:n,key:b.borderBottomRightRadius},{target:r,key:b.borderBottomLeftRadius}].forEach((function(e){(t.styleIndex[e.key]||0)>a&&t.style[e.key].replace(J,(function(t,i,o){return e.target.width=e.target.height=i,o&&(e.target.height=o),""}))}));var c=this.element,d=c.offsetWidth,f=c.offsetHeight,p=this.margin,g=d-p.left-p.right,u=f-p.top-p.bottom,y=g>0?g/2:0,w=g>0?u/2:0;return[i,o,n,r].forEach((function(e){O.test(e.width)?e.width=t.transformUnitToPx(e.width):E.test(e.width)&&(e.width=t.transformUnitToPx(e.width,g)),e.width=e.width>y?y:e.width,O.test(e.height)?e.height=t.transformUnitToPx(e.height):E.test(e.height)&&(e.height=t.transformUnitToPx(e.height,u)),e.height=e.height>w?w:e.height})),{topLeft:i,topRight:o,bottomRight:n,bottomLeft:r,maxWidth:y,maxHeight:w}},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"textShadow",{get:function(){var t=this,e=this.style[b.textShadow]||"",i=[];return e.replace(rt,(function(){for(var e=[],o=0;o<arguments.length;o++)e[o]=arguments[o];e[0];var n=e[1],r=e[2],h=e[3],l=e[4],s=e[5],a=e[6],c=e[7],d=e[8],f=e[9],p=e[10],g=e[11],u=e[12],y=e[13],w=e[14],b=e[15],m=e[16];return n?i.push({color:n,offsetX:t.transformUnitToPx(r),offsetY:t.transformUnitToPx(h),blur:t.transformUnitToPx(l)}):s?i.push({color:d,offsetX:t.transformUnitToPx(s),offsetY:t.transformUnitToPx(a),blur:t.transformUnitToPx(c)}):f?i.push({color:f,offsetX:t.transformUnitToPx(p),offsetY:t.transformUnitToPx(g),blur:0}):u?i.push({color:w,offsetX:t.transformUnitToPx(u),offsetY:t.transformUnitToPx(y),blur:0}):b&&i.push({color:"",offsetX:t.transformUnitToPx(b),offsetY:t.transformUnitToPx(m),blur:0}),""})),i},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"color",{get:function(){return this.getInheritStyle(b.color,!0)||"#000"},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"verticalAlign",{get:function(){return this.getInheritStyle(b.verticalAlign,!0)||m},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"textAlign",{get:function(){return this.getInheritStyle("".concat(b.text,"-").concat(b.align))||ft.left},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"lineHeight",{get:function(){var t=this.getInheritStyle("".concat(b.line,"-").concat(b.height),!0)||"1.2";return O.test(t)?t=parseFloat(t):N.test(t)&&(t=parseFloat(t)*this.fontSize),t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"opacity",{get:function(){var t=parseFloat(this.style[b.opacity]);return isNaN(t)?1:t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"zIndex",{get:function(){if(this.element.nodeType===l.TEXT_NODE)return this.element.parentNode.style.zIndex;var t=parseInt(this.style[b.zIndex]);return isNaN(t)?0:t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"isNoWrap",{get:function(){for(var t=this.element;t;){var e=t.style.get(b.whiteSpace);if(e)return e===b.nowrap;t=t.parentNode}return!1},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"clear",{get:function(){return this.style[b.clear]},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"overflow",{get:function(){return this.style[b.overflow]},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"isOverflow",{get:function(){var t=this.overflow;return t===b.hidden||t===b.auto},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"isHidden",{get:function(){return this.style[b.display]===b.none},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"isAbsolute",{get:function(){return this.style[b.position]===b.absolute},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"isRelative",{get:function(){return this.element.nodeType===l.TEXT_NODE?this.element.parentNode.style.isRelative:this.style[b.position]===b.relative},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"isFloat",{get:function(){var t=this.style[b.float];return t===b.left||t===b.right},enumerable:!1,configurable:!0}),t.cachedFunction={},t}(),kt=function(t){function e(){var i=t.call(this)||this;return i.width=0,i.holdLefts=[],i.holdLeftWidth=0,i.overLeftHeight=0,i.holdRights=[],i.holdRightWidth=0,i.overRightHeight=0,Object.setPrototypeOf(i,e.prototype),i}return i(e,t),e.prototype.append=function(t){return this.restWidth>=t.offsetWidth&&(this.push(t),!0)},e.prototype.push=function(){for(var e=[],i=0;i<arguments.length;i++)e[i]=arguments[i];return e=e.filter((function(t){return t.nodeType!==l.TEXT_NODE||t.displayText})),1===this.length&&"#breakholder"===this[0].nodeName&&this.pop(),t.prototype.push.apply(this,e)},Object.defineProperty(e.prototype,"first",{get:function(){return this[0]},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"last",{get:function(){return this[this.length-1]},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"usedWidth",{get:function(){return this.flows.reduce((function(t,e){return t+=e.offsetWidth}),0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"restWidth",{get:function(){return this.width-this.holdLeftWidth-this.holdRightWidth-this.usedWidth},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"floats",{get:function(){var t=[],e=[];return this.forEach((function(i){var o=i.style.get("float");"left"===o?t.push(i):"right"===o&&e.push(i)})),{left:t,right:e,all:r(r([],t,!0),e,!0)}},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"flows",{get:function(){return this.filter((function(t){return!t.style.isAbsolute}))},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"absolutes",{get:function(){var t=[];return this.forEach((function(e){e.style.isAbsolute&&t.push(e)})),t},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"textFlows",{get:function(){return this.filter((function(t){return!t.style.isFloat&&!t.style.isAbsolute}))},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"normalHeight",{get:function(){var t=this.filter((function(t){return!t.style.isFloat&&!t.style.isAbsolute})).map((function(t){return t.offsetHeight}));return 0===t.length?0:Math.max.apply(Math,t)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"floatHeight",{get:function(){var t=this.floats.all.map((function(t){return t.offsetHeight}));return 0===t.length?0:Math.max.apply(Math,t)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"height",{get:function(){return this.normalHeight},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"realWidth",{get:function(){return this.usedWidth+this.holdLeftWidth+this.holdRightWidth},enumerable:!1,configurable:!0}),e}(Array),Nt=function(t){function e(i){var o=t.call(this)||this;return Object.setPrototypeOf(o,e.prototype),o.element=i,o}return i(e,t),e.prototype.lastInheritLine=function(){var t=this[this.length-1];if(t)for(var e=t.last;e;){if(!e.lines.length){t=e.line;break}e=e.lines[e.lines.length-1].last}return t},e.prototype.lastLine=function(){return this[this.length-1]},e.prototype.newLine=function(t){var e=new kt;t&&(e.width=t);var i=this.lastLine();if(i||(i=this.element.line),i){if(1===i.length&&"#breakholder"===i.last.nodeName)return i;if(0===i.length){var o=new Lt;o.nodeName="#breakholder",o.nodeType=l.ELEMENT_NODE,o.contentHeight=this.element.root?this.element.root.textMetric.lineHeight:this.element.textMetric.lineHeight,o.line=i,o.lineElement=this.element,i.append(o)}var n=i.floats,h=i.normalHeight,s=n.left.slice().reverse().findIndex((function(t){return t.offsetHeight>h}));if(s>-1){var a=n.left.slice(0,n.left.length-s);i.holdLefts=Array.from(new Set(r(r([],i.holdLefts,!0),a,!0)))}if((s=n.right.slice().reverse().findIndex((function(t){return t.offsetHeight>h})))>-1){var c=n.right.slice(0,n.right.length-s);i.holdRights=Array.from(new Set(r(r([],i.holdRights,!0),c,!0)))}var d=Math.max.apply(Math,i.holdLefts.map((function(t){return t.offsetHeight})));if(d>0&&(i.overLeftHeight=d-h),d=0,(d=Math.max.apply(Math,i.holdRights.map((function(t){return t.offsetHeight}))))>0&&(i.overRightHeight=d-h),i.overLeftHeight>0||i.overRightHeight>0){var f=-1;i.holdLefts.forEach((function(t,e){t.offsetHeight-h>0&&(f=e)}),0),-1!==f&&(e.holdLefts=i.holdLefts.slice(0,f+1).map((function(t){var i=t.clone();return e.holdLeftWidth+=t.offsetWidth,i.contentHeight-=h,i}))),f=-1,i.holdRights.forEach((function(t,e){t.offsetHeight-h>0&&(f=e)})),-1!==f&&(e.holdRights=i.holdRights.slice(0,f+1).map((function(t){var i=t.clone();return e.holdRightWidth+=t.offsetWidth,i.contentHeight-=h,i})))}}return this.push(e),e.lines=this,e},e.prototype.lastLineOrNewLine=function(t){return this.lastLine()||this.newLine(t)},Object.defineProperty(e.prototype,"linesHeight",{get:function(){return this.reduce((function(t,e){return t+=e.height}),0)},enumerable:!1,configurable:!0}),e}(Array),Wt=function(){function t(){this.nodeValue="",this.contentWidth=0,this.contentHeight=0,this.left=0,this.top=0,this.nodeName="",this.nodeType=l.ELEMENT_NODE,this.children=[],this.shadows=[],this.shadow=null,this.style=new Pt(this),this.attrs={},this.endNode=null,this.parentNode=null,this.prevNode=null,this.nextNode=null,this.lines=new Nt(this),this.line=null,this.lineElement=null,this.debug=!1}return t.prototype.updateCache=function(){this.style.updateCache()},t.prototype.clone=function(){var e=new t;return Object.assign(e,this),e.shadow=this,e},t.prototype.getNearBlock=function(){for(var t=this.parentNode;t;){var e=t.blockType;if(e===s.block||e===s.inlineBlock)return t;t=t.parentNode}return t},t.prototype.getNearRelativeBlock=function(){for(var t=this.parentNode;t;){if(t.style.isRelative||t.style.isAbsolute)return t;if(!t.parentNode)break;t=t.parentNode}return t},t.prototype.getNearHasWidthBlock=function(){for(var t=this.getNearBlock();t;){if(t.style.width&&t.contentWidth)return t;t=t.parentNode}return null},t.prototype.isInlineORInlineBlock=function(t){return[s.inline,s.inlineBlock].includes(t.blockType)},Object.defineProperty(t.prototype,"displayText",{get:function(){var t=this.nodeValue.replace(/\s+/g," ");return" "===t?"":t.trim()},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"blockType",{get:function(){var t=this.style.get("display");return this.style.isAbsolute||this.style.isFloat?s.inlineBlock:t||(this.nodeType===l.ELEMENT_NODE||this.nodeType===l.DOCUMENT_NODE?/^(span|i|br|strong|a)$/.test(this.nodeName)?s.inline:/^(img|input|select)$/.test(this.nodeName)?s.inlineBlock:s.block:(this.nodeType,l.TEXT_NODE,s.inline))},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"offsetWidth",{get:function(){var t=this.blockType;if(this.nodeType===l.TEXT_NODE)return this.contentWidth;var e=this.style,i=e.margin,o=e.padding,n=e.border;return t===s.block||t===s.inlineBlock?this.contentWidth+i.left+i.right+n.left.width+n.right.width+o.left+o.right:t===s.inline?this.contentWidth+n.left.width+n.right.width+o.left+o.right:0},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"offsetHeight",{get:function(){var t=this.blockType;if(this.nodeType===l.TEXT_NODE)return this.contentHeight;var e=this.style,i=e.margin,o=e.padding,n=e.border;return t===s.block||t===s.inlineBlock?this.contentHeight+i.top+i.bottom+n.top.width+n.bottom.width+o.top+o.bottom:t===s.inline?this.contentHeight:0},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"offsetLeft",{get:function(){return this.lineElement?this.lineElement.offsetLeft+this.left:this.left},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"offsetTop",{get:function(){return this.lineElement?this.lineElement.offsetTop+this.top:this.top},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"innerHTML",{get:function(){return""},set:function(t){},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"firstChild",{get:function(){return this.children[0]},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"lastChild",{get:function(){return this.children[this.children.length-1]},enumerable:!1,configurable:!0}),t.prototype.getTextMetrics=function(t,e){var i=this.style,o=i.canvasFont,n=i.lineHeight;return t.font=o,{width:t.measureText(e).width,lineHeight:n}},t.prototype.layoutFixedSize=function(t){var e=this.blockType;if(this.nodeType===l.TEXT_NODE){var i=this.getTextMetrics(t,this.displayText);this.contentWidth=i.width,this.contentHeight=i.lineHeight,this.textMetric=i}else if(e===s.block||e===s.inlineBlock){var o=this.style,n=o.width,r=o.height;O.test(n)&&(this.contentWidth=this.style.transformUnitToPx(n)),O.test(r)&&(this.contentHeight=this.style.transformUnitToPx(r))}this.children.forEach((function(e){e.layoutFixedSize(t)}))},t.prototype.layoutInheritWidth=function(t){var e=this.blockType,i=this.style,o=i.width,n=i.padding,r=i.border,h=i.margin;if(!o&&(e===s.block||e===s.inlineBlock)){var l=this.getNearBlock(),a=n.left+n.right+r.left.width+r.right.width+h.left+h.right;l&&(this.contentWidth=l.contentWidth-a)}this.children.forEach((function(e){e.layoutInheritWidth(t)}))},t.prototype.layoutPercentWidth=function(t){var e=this.blockType;if(e===s.block||e===s.inlineBlock){var i=this.style.width;if(E.test(i)){var o=this.getNearBlock();o&&(this.contentWidth=this.style.transformUnitToPx(i,o.contentWidth))}if(E.test(i)){var n=this.getNearBlock();n&&n.contentHeight&&(this.contentHeight=this.style.transformUnitToPx(i,n.contentHeight))}}if(this.nodeName===a.img){var r=this,h=this.style,l=(i=h.width,h.height);if(i&&l);else if(i||l){if(this.getNearBlock())if(i){var c=this.contentWidth/r.imageWidth;this.contentHeight=r.imageHeight*c}else if(l){c=this.contentHeight/r.imageHeight;this.contentWidth=r.imageWidth*c}}else this.contentWidth=r.imageWidth,this.contentHeight=r.imageHeight}this.children.forEach((function(e){e.layoutPercentWidth(t)}))},t.prototype.layoutLine=function(e){var i=this,o=this.blockType,n=this.style.isNoWrap;if(o===s.inlineBlock||o===s.block){this.lines=new Nt(this);var r=this.lines.newLine(this.contentWidth),h=function(e,i,o){var n=new t;return n.nodeName="#placholder",n.nodeValue="",n.contentHeight=e,n.lineElement=o,n.line=i,i.push(n),n},c=function(o){if(o.nodeType!==l.COMMENT_NODE){o.lineElement=i,o.line=r;var d=o.blockType,f=o.style,p=f.clear,g=f.isOverflow;if(f.isFloat,o.nodeType===l.TEXT_NODE){var u=o.textMetric;if(n)r.push(o);else if(r.append(o))o.contentHeight=u.lineHeight;else{var y=o.displayText,w=y.length*(1-r.restWidth/u.width);w=w<1?1:w;var b=y.slice(0,-w);o.shadows=[];for(var m=function(t,e){var i=o.clone();i.nodeValue=t,i.contentWidth=e,i.contentHeight=u.lineHeight,i.textMetric=u,r.push(i),o.shadows.push(i),i.line=r,o.line=r,i.shadow=o};y.length;){if(r.restWidth<=0){if(0===r.length){m(y,(u=o.getTextMetrics(e,y)).width);break}r=i.lines.newLine(r.width),b=y}else if(""===b){if(0===r.length){m(y,(u=o.getTextMetrics(e,y)).width);break}r=i.lines.newLine(r.width),b=y;continue}var v=(u=o.getTextMetrics(e,b)).width;v<=r.restWidth?(m(b,v),b=(y=y.slice(b.length)).length>w?y.slice(0,w):y):(w=(w=b.length*(1-r.restWidth/u.width))<1?1:w,b=b.slice(0,-w))}}}else if(o.nodeType===l.ELEMENT_NODE&&d===s.inline)if(o.nodeName===a.br||o.nodeName===a.hr)o.contentHeight=i.root.textMetric.lineHeight,(r=i.lines.newLine(r.width)).push(o),o.line=r;else if(o.lines=new Nt(o),n)r.push(o),o.children.forEach(c);else{var T=function(){var t=i.lines.lastLine(),e=o.clone();return e.shadow=o,o.shadows.push(e),e.contentWidth-=e.offsetWidth/2,t.append(e)||(t=i.lines.newLine(r.width)).push(e),e.line=t,r=t,e};o.shadows=[];var x=T();o.children.forEach(c);var O=T(),E=i.children.find((function(t){return t.nodeType===l.TEXT_NODE&&t.contentHeight}));E&&(x.contentHeight=O.contentHeight=E.offsetHeight)}else{var P;if(d===s.inlineBlock){if(o.line=null,(P=i.lines.lastInheritLine())&&(P.holdLefts.length||P.holdRights.length))if(p){P.lines.newLine(0),P.lines.pop();var k=i.lines.newLine(0),N=P.lines.lastLine(),W=Math.max(N.overLeftHeight,N.overRightHeight);h(W,k,i)}else{var L=i.lines.newLine(r.width);Object.assign(L,P),r=L}}else if((P=i.lines.lastInheritLine())&&(P.holdLefts.length||P.holdRights.length))if(p){P.lines.newLine(0),P.lines.pop();k=i.lines.newLine(0),N=P.lines.lastLine(),W=Math.max(N.overLeftHeight,N.overRightHeight);h(W,k,i),o.line=null,r=k}else o.line=P;if(o.layoutLine(e),d===s.inlineBlock||g){o.lines.newLine(r.width),o.lines.pop();var M=o.lines.lastLine();if(M&&(M.overLeftHeight||M.overRightHeight)){L=o.lines.newLine(r.width),W=Math.max(M.overLeftHeight,M.overRightHeight);h(W,L,o)}}if(d===s.inlineBlock)if(o.nodeName===a.img||(o.style.width||(o.contentWidth=Math.max.apply(Math,o.lines.map((function(t){return t.realWidth})))),o.style.height||(o.contentHeight=o.lines.linesHeight)),o.style.isAbsolute){var H=o.getNearRelativeBlock()||i.root,I=H.lines.lastLineOrNewLine(H.contentWidth);if(o.lineElement=H,o.line=I,H.blockType===s.inline){var R=H.parentNode;if(!R)throw new Error("定位元素无法找到父元素");var S=R.lines.lastLineOrNewLine(R.contentWidth);S.push(o),o.line=S}else o.line=I,I.push(o)}else if(n)r.push(o);else{for(;!r.append(o);)if(0===(r=i.lines.newLine(r.width)).length){r.push(o);break}o.line=r}else d===s.block&&(!function(e){var i=e.lines.newLine(0),o=new t;o.nodeName="#empty",o.nodeValue="",o.lineElement=e,o.line=i,i.push(o)}(o),r.length&&(r=i.lines.newLine(r.width)),r.push(o),o.line=r,o.nodeName===a.img||o.style.height||(o.contentHeight=o.lines.linesHeight))}}};this.children.forEach(c),this.nodeName===a.img||this.style.height||(this.contentHeight=this.lines.linesHeight)}var d=this.lines.lastLine();d&&0===d.length&&this.lines.pop()},t.prototype.layoutLinePosition=function(){var t=this,e=this.style,i=e.margin,o=e.border,n=e.padding,r=e.textAlign,h=this.blockType,l=0,a=0,c=0;h===s.block||h===s.inlineBlock?(a=i.left+o.left.width+n.left,c=i.left+o.left.width+n.left,l=i.top+o.top.width+n.top):h===s.inline&&(a=o.left.width+n.left);var d=l,f=[];this.lines.forEach((function(e){var i=e.holdLeftWidth+a,o=e.textFlows,n=e.floats,h=e.absolutes,l=e.height,p=0,g=e.holdRightWidth;n.left.forEach((function(t){t.top=d,t.left=i+p,p+=t.offsetWidth})),n.right.forEach((function(e){e.top=d,g+=e.offsetWidth,e.left=t.contentWidth-g+c})),o.forEach((function(o){var n=0,h=t.contentWidth-e.usedWidth-e.holdLeftWidth-e.holdRightWidth;o.blockType!==s.block&&(r===ft.center?n=h/2:r===ft.right&&(n=h));var a=l-o.offsetHeight;o.left=p+i+n,o.top=d+a,i+=o.offsetWidth})),e.forEach((function(t){if(t.layoutLinePosition(),t.blockType===s.block){t.left-=e.holdLeftWidth;var i=t.style.getOriginRoundStyle(b.margin);i.left===b.auto&&i.right===b.auto&&t.line&&(t.left+=t.line.restWidth/2)}})),d+=e.height,f.push.apply(f,h)})),f.forEach((function(t){var e=t.style.get("top"),i=t.style.get("right"),o=t.style.get("bottom"),n=t.style.get("left"),r=t.lineElement,h=r.shadows||[];if(r.blockType===s.inline){if(n&&i){var l=(r=h[0]||r).left+t.style.transformUnitToPx(n);if(t.left=l,!t.style.width){var a=h[h.length-1]||r;t.contentWidth=a.left+a.contentWidth-l-t.style.transformUnitToPx(i)}}else n?(r=h[0]||r,t.left=r.left+t.style.transformUnitToPx(n)):i&&(r=h[h.length-1]||r,t.left=r.left+r.contentWidth-t.offsetWidth-t.style.transformUnitToPx(i));if(e&&o){if(r=h[0]||r,t.top=r.top+t.style.transformUnitToPx(e),!t.style.height){a=h[h.length-1]||r;t.contentHeight=a.top+a.contentHeight-t.top-t.style.transformUnitToPx(o)}}else e?(r=h[0]||r,t.top=r.top+t.style.transformUnitToPx(e)):o&&(r=h[h.length-1]||r,t.top=r.top+r.contentHeight-t.offsetHeight-t.style.transformUnitToPx(o))}else{if(n&&i){l=t.style.transformUnitToPx(n);t.left=l,t.style.width||(t.contentWidth=r.contentWidth-l-t.style.transformUnitToPx(i))}else n?t.left=t.style.transformUnitToPx(n):i&&(t.left=r.contentWidth-t.offsetWidth-t.style.transformUnitToPx(i));if(e&&o){var c=t.style.transformUnitToPx(e);t.top=c,t.style.height||(t.contentHeight=r.contentHeight-c-t.style.transformUnitToPx(o))}else e?t.top=t.style.transformUnitToPx(e):o&&(t.top=r.contentHeight-t.offsetHeight-t.style.transformUnitToPx(o))}t.layoutLinePosition()}))},t.prototype.layout=function(t){this.textMetric=this.getTextMetrics(t,""),this.layoutFixedSize(t),this.layoutInheritWidth(t),this.layoutPercentWidth(t),this.layoutLine(t),this.layoutLinePosition()},t.prototype.drawBackground=function(t,e,i){var n=this;t.save();var r=this.style,h=r.border,a=r.padding,d=r.fontSize,f=r.lineHeight,p=this.contentWidth,g=this.contentHeight,u=(f-d)/2,y=this.blockType===s.inline,w=function(t){var e=0,i=0,o=0,r=0;if(t===ct.borderBox?(e=0,i=0,o=p+a.left+a.right+h.left.width+h.right.width,r=g+a.top+a.bottom+h.top.width+h.bottom.width):t===ct.paddingBox?(e=h.left.width,i=h.top.width,o=p+a.left+a.right,r=g+a.top+a.bottom):t===ct.contentBox&&(e=h.left.width+a.left,i=h.top.width+a.top,o=p,r=g),y){var s={x:e,y:i-a.top+u,width:o,height:d+a.top+a.bottom};if(n.nodeType===l.TEXT_NODE){var c=n.parentNode;if(c){var f=c.style.padding;s.y-=f.top,s.height+=f.top+f.bottom}}return s}return{x:e,y:i,width:o,height:r}},b=w(e.clip);if(e.clip!==ct.contentBox&&e.clip!==ct.paddingBox||i&&i(),e.color&&(t.fillStyle=e.color,t.fillRect(b.x,b.y,b.width,b.height)),e.image||e.gradient){var m=this.style.getImage(e.image),v=b;e.origin!==e.clip&&(v=w(e.origin));var T=0,x=0,P=0,k=0,N=0,W=0;if(e.image?(N=m.imageWidth,W=m.imageHeight):(N=b.width,W=b.height),e.size.width===st.contain||e.size.width===st.cover){if(e.size.width===st.contain&&N>W||e.size.width===st.cover&&N<W)P=N*(L=b.width/N),k=W*L;else P=N*(L=b.height/W),k=W*L}else{if(O.test(e.size.width)?P=this.style.transformUnitToPx(e.size.width):E.test(e.size.width)&&(P=this.style.transformUnitToPx(e.size.width,b.width)),O.test(e.size.height)?k=this.style.transformUnitToPx(e.size.height):E.test(e.size.height)&&(k=this.style.transformUnitToPx(e.size.height,b.height)),e.size.width===st.auto){var L=k/W;P=k?N*L:N}if(e.size.height===st.auto){L=P/N;k=P?W*L:W}}if(0===P||0===k)return;if(O.test(e.position.leftOffset)?T=this.style.transformUnitToPx(e.position.leftOffset):E.test(e.position.leftOffset)&&(T=this.style.transformUnitToPx(e.position.leftOffset,b.width-P)),e.position.left===lt.left?T+=v.x:e.position.left===lt.right?T=b.width-P-T+v.x:e.position.left===lt.center&&(T+=b.width/2-P/2),O.test(e.position.topOffset)?x=this.style.transformUnitToPx(e.position.topOffset):E.test(e.position.topOffset)&&(x=this.style.transformUnitToPx(e.position.topOffset,b.height-k)),e.position.top===lt.top?x+=v.y:e.position.top===lt.bottom?x=b.height-k-x+v.y:e.position.top===lt.center&&(x+=b.height/2-k/2),e.gradient){var M=void 0;if(e.gradient.type===ht.linearGradient)M=function(t,e,i,o){var n=Math.PI/180*(90-o.angle),r=Math.abs(e*Math.sin(n))+Math.abs(i*Math.cos(n)),h=r/2,l=e/2,s=i/2,a=Math.cos(n)*h,c=Math.sin(n)*h,d=t.createLinearGradient(l-a,s+c,l+a,s-c);return o.list.forEach((function(t,e){var i=t.stop;O.test(i)?i=(i=parseFloat(i)/r)>1?1:i:E.test(i)?i=parseFloat(i)/100:0===e?i=0:e===o.list.length-1&&(i=1),d.addColorStop(i,t.color)})),d}(t,P,k,e.gradient);M&&c(t,o.gradient,M,P,k,T-b.x,x-b.y,b.x,b.y,b.width,b.height,e.repeat)}else m&&m.source&&c(t,o.image,m.source,P,k,T-b.x,x-b.y,b.x,b.y,b.width,b.height,e.repeat)}t.restore()},t.prototype.drawBorder=function(t,e){t.save();var i=this.style,o=i.border,n=i.radius,r=i.margin,h=i.padding,l=this,s=l.offsetLeft,c=l.offsetTop,d=l.contentHeight,f=l.contentWidth,p=o.top,g=o.right,y=o.bottom,w=o.left,b=n.topLeft,m=n.topRight,T=n.bottomRight,x=n.bottomLeft,O=n.maxWidth,E=n.maxHeight,P=s+r.left,k=c+r.top,N=f+h.left+h.right+o.left.width+o.right.width,W=d+h.top+h.bottom+o.top.width+o.bottom.width;t.lineCap="butt",t.translate(P,k);var L=!(0===b.width&&0===b.height&&0===m.width&&0===m.height&&0===T.width&&0===T.height&&0===x.width&&0===x.height),M=!(0===p.width&&0===g.width&&0===y.width&&0===w.width),H=p.width===g.width&&g.width===y.width&&y.width===w.width&&w.width===p.width,I=p.color===g.color&&g.color===y.color&&y.color===w.color&&w.color===p.color,R=p.style===g.style&&g.style===y.style&&y.style===w.style&&w.style===p.style,S=b.width===O&&b.height===E&&m.width===O&&m.height===E&&T.width===O&&T.height===E&&x.width===O&&x.height===E,j=Math.PI/180,_=function(e){switch(e.style){case v.solid:t.setLineDash([]);break;case v.dashed:t.setLineDash([2*e.width,e.width])}},D=function(){t.beginPath(),b.width-w.width>0&&b.height-p.width>0?u(t,b.width,b.height,b.width-w.width,b.height-p.width,0,Math.PI,-90*j):t.moveTo(w.width,p.width),m.width-g.width>0&&m.height-p.width>0?u(t,N-m.width,m.height,m.width-g.width,m.height-p.width,0,-90*j,0):t.lineTo(N-g.width,p.width),T.width-g.width>0&&T.height-y.width>0?u(t,N-T.width,W-T.height,T.width-g.width,T.height-y.width,0,0,90*j):t.lineTo(N-g.width,W-y.width),x.width-w.width>0&&x.height-y.width>0?u(t,x.width,W-x.height,x.width-w.width,x.height-y.width,0,90*j,Math.PI):t.lineTo(w.width,W-y.width),t.closePath()},U=function(){t.lineWidth=1,t.strokeStyle="transparent",t.stroke(),t.clip()};if(L){if(H&&R&&I&&S){if("function"==typeof e){t.save(),t.beginPath();var B=0;this.nodeName===a.img&&(B=p.width),u(t,N/2,W/2,N/2-B,W/2-B,0,0,2*Math.PI),U(),e(t),t.restore()}M&&(t.beginPath(),u(t,N/2,W/2,N/2-p.width/2,W/2-p.width/2,0,0,2*Math.PI),t.lineWidth=p.width,t.strokeStyle=p.color,_(p),t.stroke())}else if(t.save(),t.beginPath(),b.width>0&&b.height>0?u(t,b.width,b.height,b.width,b.height,0,Math.PI,-90*j):t.moveTo(0,0),m.width>0&&m.height>0?u(t,N-m.width,m.height,m.width,m.height,0,-90*j,0):t.lineTo(N,0),T.width>0&&T.height>0?u(t,N-T.width,W-T.height,T.width,T.height,0,0,90*j):t.lineTo(N,W),x.width>0&&x.height>0?u(t,x.width,W-x.height,x.width,x.height,0,90*j,Mat