draw-html-to-canvas
Version:
根据html+css规范绘制 网页到canvas
1 lines • 61.1 kB
JavaScript
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=function(e,i){return t=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])},t(e,i)};function e(e,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=e}t(e,i),e.prototype=null===i?Object.create(i):(o.prototype=i.prototype,new o)}var i,o=function(){return o=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},o.apply(this,arguments)};function n(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"}(i||(i={}));var r,h,s,l,a=function(t,e,o,n,r,h,s,l,a,c,d,f,p){t.save(),t.translate(l,a),t.beginPath(),t.rect(0,0,c,d),t.clip();var g=-Math.ceil(h/n)*n+h,u=-Math.ceil(s/r)*r+s,y=Math.ceil(d/r)+1,w=Math.ceil(c/n)+1,b=!1;if(e===i.gradient&&(t.fillStyle=o,b=!0),f===st.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===i.image?t.drawImage(o,g+T,u+x,n,r):e===i.gradient&&(t.fillRect(0,0,n,r),t.translate(n,0))}b&&t.translate(-w*n,r)}}else if(f===st.repeatY){b&&t.translate(h,u);for(m=0;m<y;m++){x=m*r;e===i.image?t.drawImage(o,h,x+u,n,r):e===i.gradient&&(t.fillRect(0,0,n,r),t.translate(0,r))}}else if(f===st.repeatX){b&&t.translate(g,s);for(v=0;v<w;v++){T=v*n;e===i.image?t.drawImage(o,T+g,s,n,r):e===i.gradient&&(t.fillRect(0,0,n,r),t.translate(n,0))}}else f===st.noRepeat&&(e===i.image?t.drawImage(o,h,s,n,r):e===i.gradient&&(t.translate(h,s),t.fillRect(0,0,n,r)));"function"==typeof p&&p(t),t.restore()},c=function(t){return Object.values?Object.values(t):Object.keys(t).map((function(e){return t[e]}))},d=function(t,e,i,o,n){var r=(1-n)*t+e*n,h=(1-n)*e+i*n,s=(1-n)*r+h*n;return[t,r,s,(1-n)*s+((1-n)*h+((1-n)*i+o*n)*n)*n]},f=function(t,e,i,o,n){var r=(1-n)*e+i*n,h=(1-n)*i+o*n,s=(1-n)*r+h*n;return[(1-n)*((1-n)*((1-n)*t+e*n)+r*n)+s*n,s,h,o]},p=function(t,e,i,o,n,r){var h=d(t,e,i,o,r),s=h[0],l=h[1],a=h[2],c=h[3];return f(s,l,a,c,n/r)},g=function(t,e,i,o,r,h,s,l,a){if(t.ellipse)return t.ellipse(e,i,o,r,h,s,l,a);var c=Math.PI/180,g=s/c,u=l/c;if(0!==o&&0!==r&&g!==u){var y=.5522848,w=o*y,b=r*y,m=e+o,v=i+r;if(t.save(),t.translate(e,i),t.rotate(h),t.translate(-e,-i),g<0){var T=Math.abs(g),x=T%360,O=Math.ceil(T/360);if(g=360*O-x,u<0){var E=(P=Math.abs(u))%360;(u=360*(k=Math.ceil(P/360))-E)<g&&(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,g+=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-r],[e,i-r]],[[e,i-r],[e+w,i-r],[m,i-b],[m,i]]],W=0,L=[];g+W<u;){var M=g+W,H=Math.floor(M/90)%4;L.push(N[H]),W+=0===W&&g%90!=0?90-g%90:90}L.length&&(1===L.length&&g%90!=0&&u%90!=0?L[0]=function(t,e,i){var o=t[0],n=t[1],r=t[2],h=t[3],s=p(o[0],n[0],r[0],h[0],e,i),l=p(o[1],n[1],r[1],h[1],e,i);return[[s[0],l[0]],[s[1],l[1]],[s[2],l[2]],[s[3],l[3]]]}(L[0],g%90/90,u%90/90):(g%90!=0&&(L[0]=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),s=f(i[1],o[1],n[1],r[1],e);return[[h[0],s[0]],[h[1],s[1]],[h[2],s[2]],[h[3],s[3]]]}(L[0],g%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=d(i[0],o[0],n[0],r[0],e),s=d(i[1],o[1],n[1],r[1],e);return[[h[0],s[0]],[h[1],s[1]],[h[2],s[2]],[h[3],s[3]]]}(L[L.length-1],u%90/90))),L.forEach((function(e,i){var o=e[0],r=e[1],h=e[2],s=e[3];0===i&&t.lineTo.apply(t,o),t.bezierCurveTo.apply(t,n(n(n([],r,!1),h,!1),s,!1))}))),t.restore()}},u=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},y=u({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:""}),w=u(o(o({},y),((r={"vertical-align":"","white-space":"","z-index":""})["".concat(y.font,"-").concat(y.style)]="",r["".concat(y.font,"-").concat(y.variant)]="",r["".concat(y.font,"-").concat(y.weight)]="",r["".concat(y.font,"-").concat(y.stretch)]="",r["".concat(y.font,"-").concat(y.size)]="",r["".concat(y.font,"-").concat(y.family)]="",r["".concat(y.line,"-").concat(y.height)]="",r["".concat(y.text,"-").concat(y.decoration)]="",r["".concat(y.text,"-").concat(y.decoration,"-").concat(y.color)]="",r["".concat(y.text,"-").concat(y.decoration,"-").concat(y.style)]="",r["".concat(y.text,"-").concat(y.decoration,"-").concat(y.thickness)]="",r["".concat(y.text,"-").concat(y.decoration,"-").concat(y.line)]="",r["".concat(y.background,"-").concat(y.image)]="",r["".concat(y.background,"-").concat(y.color)]="",r["".concat(y.background,"-").concat(y.position)]="",r["".concat(y.background,"-").concat(y.size)]="",r["".concat(y.background,"-").concat(y.repeat)]="",r["".concat(y.background,"-").concat(y.clip)]="",r["".concat(y.background,"-").concat(y.origin)]="",r["".concat(y.border,"-").concat(y.top)]="",r["".concat(y.border,"-").concat(y.right)]="",r["".concat(y.border,"-").concat(y.bottom)]="",r["".concat(y.border,"-").concat(y.left)]="",r["".concat(y.border,"-").concat(y.top,"-").concat(y.width)]="",r["".concat(y.border,"-").concat(y.right,"-").concat(y.width)]="",r["".concat(y.border,"-").concat(y.bottom,"-").concat(y.width)]="",r["".concat(y.border,"-").concat(y.left,"-").concat(y.width)]="",r["".concat(y.border,"-").concat(y.top,"-").concat(y.style)]="",r["".concat(y.border,"-").concat(y.right,"-").concat(y.style)]="",r["".concat(y.border,"-").concat(y.bottom,"-").concat(y.style)]="",r["".concat(y.border,"-").concat(y.left,"-").concat(y.style)]="",r["".concat(y.border,"-").concat(y.top,"-").concat(y.color)]="",r["".concat(y.border,"-").concat(y.right,"-").concat(y.color)]="",r["".concat(y.border,"-").concat(y.bottom,"-").concat(y.color)]="",r["".concat(y.border,"-").concat(y.left,"-").concat(y.color)]="",r["".concat(y.border,"-").concat(y.radius)]="",r["".concat(y.border,"-").concat(y.top,"-").concat(y.left,"-").concat(y.radius)]="",r["".concat(y.border,"-").concat(y.top,"-").concat(y.right,"-").concat(y.radius)]="",r["".concat(y.border,"-").concat(y.bottom,"-").concat(y.right,"-").concat(y.radius)]="",r["".concat(y.border,"-").concat(y.bottom,"-").concat(y.left,"-").concat(y.radius)]="",r["".concat(y.text,"-").concat(y.shadow)]="",r["".concat(y.box,"-").concat(y.shadow)]="",r))),b=w.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"}(h||(h={})),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"}(l||(l={}));var m,v="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",T=new RegExp(v,"i"),x=/px$/i,O=/%$/,E=/rem$/i,P=/em$/i,k=/^\d+(?:.\d+)?$/,N=/url\((?:'([^']+)'|("[^"]+")|([^)]+))\)/i,W=/repeat-y|repeat-x|no-repeat|repeat/i,L=/scroll|fixed|local/i,M=/border-box|padding-box|content-box/gi,H="(?:-?\\d*(?:\\.\\d+)?)(?:%|px)?",R="(".concat(H,")"),I="left|center|right|top|bottom",S="(".concat(I,")"),j="(?:(".concat(I,")\\s+").concat(R,"?)"),_="(auto|".concat(H,")"),U="(?:".concat("(cover|contain)","|(?:").concat(_,"(?:\\s+").concat(_,")?))"),D=new RegExp(I,"i"),B=/left|right/,C=/top|bottom/,z=new RegExp("(?:".concat(S,"\\s+").concat(R,"\\s+").concat(S,"\\s+").concat(R,")|(?:").concat(S,"\\s+((?:").concat(I,")|").concat(H,")\\s+((?:").concat(I,")|").concat(H,"))|(?:(?:").concat(S,"|").concat(R,")\\s+(?:").concat(S,"|").concat(R,"))|(?:").concat(S,"|").concat(R,")"),"i"),F=new RegExp(U,"i"),A=new RegExp("\\s*(".concat(j,"|").concat(R,")(?:\\s*(").concat(j,"|").concat(R,"))?(?:\\s*\\/\\s*").concat(U,")"),"i"),X=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,"))")},Y=new RegExp(X("auto|".concat(H)),"i"),G=X("(?:\\d*(?:\\.\\d+)?)(?:%|px)?"),V=new RegExp("(?:".concat(G,"(?:\\s*/\\s*").concat(G,")?)"),"i"),$=new RegExp("(".concat("(?:\\d*(?:\\.\\d+)?)(?:%|px)?",")(?:\\s+(").concat("(?:\\d*(?:\\.\\d+)?)(?:%|px)?","))?"),"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"}(m||(m={}));var q,J,K="(".concat(c(m).join("|"),")"),Q="((?:thin|medium|thick)|(?:".concat("(?:\\d*(?:\\.\\d+)?)(?:%|px)?","))"),Z=new RegExp(Q,"i"),tt=new RegExp(K,"i"),et=T,it=new RegExp("".concat(Q,"\\s+").concat(K,"\\s+(").concat(v,")"),"i"),ot=new RegExp("(?:\\s*,\\s*)?(?:"+["(".concat(v,")\\s+(").concat(H,")\\s+(").concat(H,")\\s+(").concat(H,")"),"(".concat(H,")\\s+(").concat(H,")\\s+(").concat(H,")\\s+(").concat(v,")"),"(".concat(v,")\\s+(").concat(H,")\\s+(").concat(H,")"),"(".concat(H,")\\s+(").concat(H,")\\s+(").concat(v,")"),"(".concat(H,")\\s+(").concat(H,")")].join("|")+")(?:\\s*,\\s*)?","ig");!function(t){t.none="none",t.underline="underline",t.overline="overline",t.lineThrough="line-through"}(q||(q={})),function(t){t.solid="solid",t.double="double",t.dotted="dotted",t.dashed="dashed",t.wavy="wavy"}(J||(J={}));var nt,rt,ht,st,lt,at,ct,dt=new RegExp("".concat(c(J).join("|")),"i"),ft=new RegExp("".concat(c(q).join("|")),"ig"),pt=T,gt=new RegExp("(?:\\d*(?:\\.\\d+)?)(?:%|px)?".slice(0,-1),"i"),ut=/((?:repeating-)?(?:linear|radial)-gradient)/i,yt=/((?: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,wt=new RegExp("(".concat(v,")(\\s+").concat(H,")?"),"gi"),bt=/([^\s]+)\s*=\s*('([^']+)'|"([^"]+)"|([^=<>"']))?/gi,mt=/\s*([^:]+)\s*:\s*([^;]+)\s*;?/gi,vt=/br|hr|area|base|img|input|link|meta|basefont|param|col|frame|embed|keygen|source/gi,Tt=new RegExp("#__URL__#","g");!function(t){t.repeatingLinearGradient="repeating-linear-gradient",t.repeatingRadialGradient="repeating-radial-gradient",t.linearGradient="linear-gradient",t.radialGradient="radial-gradient"}(nt||(nt={})),function(t){t.left="left",t.center="center",t.right="right",t.top="top",t.bottom="bottom"}(rt||(rt={})),function(t){t.auto="auto",t.cover="cover",t.contain="contain"}(ht||(ht={})),function(t){t.repeat="repeat",t.noRepeat="no-repeat",t.repeatX="repeat-x",t.repeatY="repeat-y"}(st||(st={})),function(t){t.borderBox="border-box",t.paddingBox="padding-box",t.contentBox="content-box"}(lt||(lt={})),function(t){t.scroll="scroll",t.fixed="fixed",t.local="local"}(at||(at={})),function(t){t.left="left",t.center="center",t.right="right"}(ct||(ct={}));var xt=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!==w.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(Y,(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],s=e[4],l=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=s):l?(n.top=l,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=[w.top,w.right,w.bottom,w.left],o=this.getOriginRoundStyle(t);return i.forEach((function(t){o[t]===w.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(x.test(t))return parseFloat(t);if(!e)throw new Error("missing unit [".concat(t,"]"));return O.test(t)?e*parseFloat(t)/100:E.test(t)||P.test(t)?e*parseFloat(t):parseFloat(t)},Object.defineProperty(t.prototype,"canvasFont",{get:function(){var t=this.getInheritStyle(w.fontStyle,!0),e=this.getInheritStyle(w.fontVariant,!0),i=this.getInheritStyle(w.fontWeight,!0),o=this.getInheritStyle(w.fontStretch,!0),n=this.fontSize,r=this.getInheritStyle(w.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(w.fontSize,!0)||"16px";return parseInt(t)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"textDecoration",{get:function(){var t=this,e=this.getInheritStyle(w.textDecoration),i=[],o="#000",n="",r=1,h=!1;return"".concat(e).replace(pt,(function(t){return o=t,""})).replace(dt,(function(t){return n=t,""})).replace(gt,(function(e){return r=t.transformUnitToPx(e),""})).replace(ft,(function(t){return t===w.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===h.TEXT_NODE&&(e=e.parentNode)&&e.blockType!==s.inline)return[];if(!e)return[];var i=function(t){var e=t.split(ut),i=[];return e.reduce((function(t,e){return ut.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 s=e.slice(0,r+1),l={};return s.replace(yt,(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],s=e[4],a=e[5],c=e[6],d=e[7],f=e[8];return n?r||s?(s&&(r=a,h=s),f=r===w.top?h===w.left?-45:45:h===w.left?225:-225):c?f=c===w.top?0:180:d?f=d===w.left?270:90:f&&(f=parseFloat(f)):f=180,l={type:o,angle:f,list:[]},""})).replace(wt,(function(t,e,i){return l.list.push({color:e,stop:i}),""})),t=t.replace(s,""),i.push(l),s})),{restStyle:t,gradients:i}},o=e.style.style[w.background],n=e.style.styleIndex[w.background]||0,r=[],l=[];if(ut.test(o)){var a=i(o);l=a.gradients,o=a.restStyle}var c="".concat(o||"").replace(T,(function(t){return r.push(t),""})).split(",");r.length>1&&(c=[]);var d=c.map((function(t,e){var i="",o="",n={left:rt.left,leftOffset:"",top:rt.top,topOffset:""},h={width:ht.auto,height:ht.auto},s=st.repeat,a=lt.borderBox,d="",f=at.scroll,p=l[e];return e===c.length-1&&(i=r[0]),t.replace(N,(function(t,e,i,n){if(p)throw new Error("渐变和背景图不能一起使用");return o=e||i||n,""})).replace(W,(function(t){return s=t,""})).replace(M,(function(t){return a=d?t:d=t,""})).replace(L,(function(t){return f=t,""})).replace(A,(function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var i=t[1],o=t[2],r=t[3],s=t[4],l=t[5],a=t[6],c=t[7],d=t[8],f=t[9],p=t[10],g=t[11];return r&&!l&&(c=r,r=""),i&&(n.left=o||s,s&&(n.leftOffset=n.left,n.left=rt.left)),r&&(n.leftOffset=r),l?(n.top=a||d,d&&(n.topOffset=n.top,n.top=rt.top)):o&&o===rt.center&&(n.top=rt.center),c&&(n.topOffset=c),f?h.height=h.width=f:(p&&(h.width=p),g&&(h.height=g)),""})),d=d||lt.paddingBox,{color:i,image:o,gradient:p,position:n,size:h,repeat:s,attachment:f,origin:d,clip:a}})),f=function(){return{color:"",image:"",position:{left:rt.left,leftOffset:"",top:rt.top,topOffset:""},size:{width:ht.auto,height:ht.auto},repeat:st.repeat,clip:lt.borderBox,origin:lt.paddingBox,attachment:at.scroll}},p=this.style[w.backgroundImage],g=this.styleIndex[w.backgroundImage]||0,u=this.style[w.backgroundColor],y=this.styleIndex[w.backgroundColor]||0,b=this.style[w.backgroundPosition],m=this.styleIndex[w.backgroundPosition]||0,v=this.style[w.backgroundSize],x=this.styleIndex[w.backgroundSize]||0,O=this.style[w.backgroundRepeat],E=this.styleIndex[w.backgroundRepeat]||0,P=this.style[w.backgroundClip],k=this.styleIndex[w.backgroundClip]||0,H=this.style[w.backgroundOrigin],R=this.styleIndex[w.backgroundOrigin]||0;(m>n&&b.split(",").forEach((function(e,i){e.trim().replace(z,(function(e){for(var o=[],n=1;n<arguments.length;n++)o[n-1]=arguments[n];var r=o[0],h=o[1],s=o[2],l=o[3],a=o[4],c=o[5],p=o[6],g=o[7],u=o[8],y=o[9],b=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=s,T.topOffset=l):a?B.test(a)||a===w.center?(T.left=a,D.test(c)?(T.leftOffset="",T.top=c,D.test(p)?console.warn("语法错误 background-position: ".concat(t.style[w.backgroundPosition]),t.element):T.topOffset=p):(T.leftOffset=c,C.test(p)?(T.top=p,T.topOffset=""):console.warn("语法错误 background-position: ".concat(t.style[w.backgroundPosition]),t.element))):C.test(a)&&(T.top=a,D.test(c)?(T.topOffset="",T.left=c,D.test(p)?console.warn("语法错误 background-position: ".concat(t.style[w.backgroundPosition]),t.element):T.leftOffset=p):(T.topOffset=c,D.test(p)?(T.top=p,T.topOffset=""):console.warn("语法错误 background-position: ".concat(t.style[w.backgroundPosition]),t.element))):g||u||y||b?g&&y?(B.test(g)?(T.left=g,T.top=y):(T.left=y,T.top=g),T.leftOffset="",T.topOffset=""):u&&b?(T.left=w.left,T.top=w.top,T.leftOffset=u,T.topOffset=b):g&&b?B.test(g)?(T.left=g,T.leftOffset="",T.top=w.top,T.topOffset=b):(T.top=g,T.topOffset="",T.left=w.left,T.leftOffset=b):u&&y&&(C.test(y)?(T.left=w.left,T.leftOffset=u,T.top=y,T.topOffset=""):console.warn("背景位置无效 不允许出现 [10px left|right] 格式",t.element)):(m||v)&&(m?B.test(m)?(T.left=m,T.leftOffset="",T.top=w.top,T.topOffset="50%"):C.test(m)?(T.left=w.left,T.leftOffset="50%",T.top=m,T.topOffset=""):(T.left=w.center,T.leftOffset="",T.top=w.center,T.topOffset=""):(T.left=w.left,T.leftOffset=v,T.top=w.top,T.topOffset="50%")),""}))})),x>n&&v.split(",").forEach((function(t,e){t.trim().replace(F,(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 s=d[e].size;return n?s.width=n:(r&&(s.width=r),s.height=h||w.auto),""}))})),g>n)&&(ut.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(N,(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(W,(function(t){return d[e]||d.push(f()),d[e].repeat=t,""}))})),k>n&&P.split(",").forEach((function(t,e){t.replace(M,(function(t){return d[e]||d.push(f()),d[e].clip=t,""}))})),R>n&&H.split(",").forEach((function(t,e){t.replace(M,(function(t){return d[e]||d.push(f()),d[e].origin=t,""}))})),y>n&&T.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[w.width]},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"height",{get:function(){return this.style[w.height]},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"padding",{get:function(){var t=this.element;if(t.nodeType===h.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(w.padding)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"margin",{get:function(){return this.getRoundStyle(w.margin)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"border",{get:function(){var t=this,e=this.element;if(e.nodeType===h.TEXT_NODE)return(e=e.parentNode)&&e.blockType===s.inline?e.style.border:{top:{width:0,style:m.none,color:"",image:""},right:{width:0,style:m.none,color:"",image:""},bottom:{width:0,style:m.none,color:"",image:""},left:{width:0,style:m.none,color:"",image:""}};var i=function(e){var i={width:0,style:"",color:"",image:""};return"".concat(e||"").replace(it,(function(e,o,n,r){return i.width=t.transformUnitToPx(o),i.style=n,i.color=r,""})),i},n=function(e){return Z.test(e)?t.transformUnitToPx(e):0},r=function(t){return tt.test(t)?t:""},l=function(t){return et.test(t)?t:""},a=i(this.style[w.border]),c=this.styleIndex[w.border]||0,d=o({},a),f=o({},a),p=o({},a),g=o({},a),u=[this.style[w.borderTop]?i(this.style[w.borderTop]):d,this.style[w.borderRight]?i(this.style[w.borderRight]):f,this.style[w.borderBottom]?i(this.style[w.borderBottom]):p,this.style[w.borderLeft]?i(this.style[w.borderLeft]):g],y=[this.styleIndex[w.borderTop]||0,this.styleIndex[w.borderRight]||0,this.styleIndex[w.borderBottom]||0,this.styleIndex[w.borderLeft]||0],b=[n(this.style[w.borderTopWidth]),n(this.style[w.borderRightWidth]),n(this.style[w.borderBottomWidth]),n(this.style[w.borderLeftWidth])];[this.styleIndex[w.borderTopWidth]||0,this.styleIndex[w.borderRightWidth]||0,this.styleIndex[w.borderBottomWidth]||0,this.styleIndex[w.borderLeftWidth]||0].forEach((function(t,e){t>y[e]&&(u[e].width=b[e])}));var v=[r(this.style[w.borderTopStyle]),r(this.style[w.borderRightStyle]),r(this.style[w.borderBottomStyle]),r(this.style[w.borderLeftStyle])];[this.styleIndex[w.borderTopStyle]||0,this.styleIndex[w.borderRightStyle]||0,this.styleIndex[w.borderBottomStyle]||0,this.styleIndex[w.borderLeftStyle]||0].forEach((function(t,e){t>y[e]&&(u[e].style=v[e])}));var T=[l(this.style[w.borderTopColor]),l(this.style[w.borderRightColor]),l(this.style[w.borderBottomColor]),l(this.style[w.borderLeftColor])];return[this.styleIndex[w.borderTopColor]||0,this.styleIndex[w.borderRightColor]||0,this.styleIndex[w.borderBottomColor]||0,this.styleIndex[w.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===h.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},l=this.style[w.borderRadius],a=this.styleIndex[w.borderRadius]||0;l&&l.replace(V,(function(t){for(var e=[],h=1;h<arguments.length;h++)e[h-1]=arguments[h];e[0];var s=e[1],l=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 s?(i.width=i.height=s,o.width=o.height=l,n.width=n.height=a,r.width=r.height=c):d?(i.width=i.height=s,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:w.borderTopLeftRadius},{target:o,key:w.borderTopRightRadius},{target:n,key:w.borderBottomRightRadius},{target:r,key:w.borderBottomLeftRadius}].forEach((function(e){(t.styleIndex[e.key]||0)>a&&t.style[e.key].replace($,(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,b=g>0?u/2:0;return[i,o,n,r].forEach((function(e){x.test(e.width)?e.width=t.transformUnitToPx(e.width):O.test(e.width)&&(e.width=t.transformUnitToPx(e.width,g)),e.width=e.width>y?y:e.width,x.test(e.height)?e.height=t.transformUnitToPx(e.height):O.test(e.height)&&(e.height=t.transformUnitToPx(e.height,u)),e.height=e.height>b?b:e.height})),{topLeft:i,topRight:o,bottomRight:n,bottomLeft:r,maxWidth:y,maxHeight:b}},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"textShadow",{get:function(){var t=this,e=this.style[w.textShadow]||"",i=[];return e.replace(ot,(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],s=e[4],l=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(s)}):l?i.push({color:d,offsetX:t.transformUnitToPx(l),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(w.color,!0)||"#000"},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"verticalAlign",{get:function(){return this.getInheritStyle(w.verticalAlign,!0)||b},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"textAlign",{get:function(){return this.getInheritStyle("".concat(w.text,"-").concat(w.align))||ct.left},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"lineHeight",{get:function(){var t=this.getInheritStyle("".concat(w.line,"-").concat(w.height),!0)||"1.2";return x.test(t)?t=parseFloat(t):k.test(t)&&(t=parseFloat(t)*this.fontSize),t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"opacity",{get:function(){var t=parseFloat(this.style[w.opacity]);return isNaN(t)?1:t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"zIndex",{get:function(){if(this.element.nodeType===h.TEXT_NODE)return this.element.parentNode.style.zIndex;var t=parseInt(this.style[w.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(w.whiteSpace);if(e)return e===w.nowrap;t=t.parentNode}return!1},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"clear",{get:function(){return this.style[w.clear]},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"overflow",{get:function(){return this.style[w.overflow]},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"isOverflow",{get:function(){var t=this.overflow;return t===w.hidden||t===w.auto},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"isHidden",{get:function(){return this.style[w.display]===w.none},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"isAbsolute",{get:function(){return this.style[w.position]===w.absolute},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"isRelative",{get:function(){return this.element.nodeType===h.TEXT_NODE?this.element.parentNode.style.isRelative:this.style[w.position]===w.relative},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"isFloat",{get:function(){var t=this.style[w.float];return t===w.left||t===w.right},enumerable:!1,configurable:!0}),t.cachedFunction={},t}(),Ot=function(t){function i(){var e=t.call(this)||this;return e.width=0,e.holdLefts=[],e.holdLeftWidth=0,e.overLeftHeight=0,e.holdRights=[],e.holdRightWidth=0,e.overRightHeight=0,Object.setPrototypeOf(e,i.prototype),e}return e(i,t),i.prototype.append=function(t){return this.restWidth>=t.offsetWidth&&(this.push(t),!0)},i.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!==h.TEXT_NODE||t.displayText})),1===this.length&&"#breakholder"===this[0].nodeName&&this.pop(),t.prototype.push.apply(this,e)},Object.defineProperty(i.prototype,"first",{get:function(){return this[0]},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"last",{get:function(){return this[this.length-1]},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"usedWidth",{get:function(){return this.flows.reduce((function(t,e){return t+=e.offsetWidth}),0)},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"restWidth",{get:function(){return this.width-this.holdLeftWidth-this.holdRightWidth-this.usedWidth},enumerable:!1,configurable:!0}),Object.defineProperty(i.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:n(n([],t,!0),e,!0)}},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"flows",{get:function(){return this.filter((function(t){return!t.style.isAbsolute}))},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"absolutes",{get:function(){var t=[];return this.forEach((function(e){e.style.isAbsolute&&t.push(e)})),t},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"textFlows",{get:function(){return this.filter((function(t){return!t.style.isFloat&&!t.style.isAbsolute}))},enumerable:!1,configurable:!0}),Object.defineProperty(i.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(i.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(i.prototype,"height",{get:function(){return this.normalHeight},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"realWidth",{get:function(){return this.usedWidth+this.holdLeftWidth+this.holdRightWidth},enumerable:!1,configurable:!0}),i}(Array),Et=function(t){function i(e){var o=t.call(this)||this;return Object.setPrototypeOf(o,i.prototype),o.element=e,o}return e(i,t),i.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},i.prototype.lastLine=function(){return this[this.length-1]},i.prototype.newLine=function(t){var e=new Ot;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 kt;o.nodeName="#breakholder",o.nodeType=h.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 r=i.floats,s=i.normalHeight,l=r.left.slice().reverse().findIndex((function(t){return t.offsetHeight>s}));if(l>-1){var a=r.left.slice(0,r.left.length-l);i.holdLefts=Array.from(new Set(n(n([],i.holdLefts,!0),a,!0)))}if((l=r.right.slice().reverse().findIndex((function(t){return t.offsetHeight>s})))>-1){var c=r.right.slice(0,r.right.length-l);i.holdRights=Array.from(new Set(n(n([],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-s),d=0,(d=Math.max.apply(Math,i.holdRights.map((function(t){return t.offsetHeight}))))>0&&(i.overRightHeight=d-s),i.overLeftHeight>0||i.overRightHeight>0){var f=-1;i.holdLefts.forEach((function(t,e){t.offsetHeight-s>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-=s,i}))),f=-1,i.holdRights.forEach((function(t,e){t.offsetHeight-s>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-=s,i})))}}return this.push(e),e.lines=this,e},i.prototype.lastLineOrNewLine=function(t){return this.lastLine()||this.newLine(t)},Object.defineProperty(i.prototype,"linesHeight",{get:function(){return this.reduce((function(t,e){return t+=e.height}),0)},enumerable:!1,configurable:!0}),i}(Array),Pt=function(){function t(){this.nodeValue="",this.contentWidth=0,this.contentHeight=0,this.left=0,this.top=0,this.nodeName="",this.nodeType=h.ELEMENT_NODE,this.children=[],this.shadows=[],this.shadow=null,this.style=new xt(this),this.attrs={},this.endNode=null,this.parentNode=null,this.prevNode=null,this.nextNode=null,this.lines=new Et(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===h.ELEMENT_NODE||this.nodeType===h.DOCUMENT_NODE?/^(span|i|br|strong|a)$/.test(this.nodeName)?s.inline:/^(img|input|select)$/.test(this.nodeName)?s.inlineBlock:s.block:(this.nodeType,h.TEXT_NODE,s.inline))},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"offsetWidth",{get:function(){var t=this.blockType;if(this.nodeType===h.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===h.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===h.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;x.test(n)&&(this.contentWidth=this.style.transformUnitToPx(n)),x.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(O.test(i)){var o=this.getNearBlock();o&&(this.contentWidth=this.style.transformUnitToPx(i,o.contentWidth))}if(O.test(i)){var n=this.getNearBlock();n&&n.contentHeight&&(this.contentHeight=this.style.transformUnitToPx(i,n.contentHeight))}}if(this.nodeName===l.img){var r=this,h=this.style,a=(i=h.width,h.height);if(i&&a);else if(i||a){if(this.getNearBlock())if(i){var c=this.contentWidth/r.imageWidth;this.contentHeight=r.imageHeight*c}else if(a){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 Et(this);var r=this.lines.newLine(this.contentWidth),a=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!==h.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===h.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===h.ELEMENT_NODE&&d===s.inline)if(o.nodeName===l.br||o.nodeName===l.hr)o.contentHeight=i.root.textMetric.lineHeight,(r=i.lines.newLine(r.width)).push(o),o.line=r;else if(o.lines=new Et(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===h.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);a(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);a(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);a(W,L,o)}}if(d===s.inlineBlock)if(o.nodeName===l.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,R=H.lines.lastLineOrNewLine(H.contentWidth);if(o.lineElement=H,o.line=R,H.blockType===s.inline){var I=H.parentNode;if(!I)throw new Error("定位元素无法找到父元素");var S=I.lines.lastLineOrNewLine(I.contentWidth);S.push(o),o.line=S}else o.line=R,R.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===l.img||o.style.height||(o.contentHeight=o.lines.linesHeight))}}};this.children.forEach(c),this.nodeName===l.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===ct.center?n=h/2:r===ct.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(w.margin);i.left===w.auto&&i.right===w.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,o){var n=this;t.save();var r=this.style,l=r.border,c=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===lt.borderBox?(e=0,i=0,o=p+c.left+c.right+l.left.width+l.right.width,r=g+c.top+c.bottom+l.top.width+l.bottom.width):t===lt.paddingBox?(e=l.left.width,i=l.top.width,o=p+c.left+c.right,r=g+c.top+c.bottom):t===lt.contentBox&&(e=l.left.width+c.left,i=l.top.width+c.top,o=p,r=g),y){var s={x:e,y:i-c.top+u,width:o,height:d+c.top+c.bottom};if(n.nodeType===h.TEXT_NODE){var a=n.parentNode;if(a){var f=a.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!==lt.contentBox&&e.clip!==lt.paddingBox||o&&o(),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,E=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===ht.contain||e.size.width===ht.cover){if(e.size.width===ht.contain&&N>W||e.size.width===ht.cover&&N<W)P=N*(L=b.width/N),k=W*L;else P=N*(L=b.height/W),k=W*L}else{if(x.test(e.size.width)?P=this.style.transformUnitToPx(e.size.width):O.test(e.size.width)&&(P=this.style.transformUnitToPx(e.size.width,b.width)),x.test(e.size.height)?k=this.style.transformUnitToPx(e.size.height):O.test(e.size.height)&&(k=this.style.transformUnitToPx(e.size.height,b.height)),e.size.width===ht.auto){var L=k/W;P=k?N*L:N}if(e.size.height===ht.auto){L=P/N;k=P?W*L:W}}if(0===P||0===k)return;if(x.test(e.position.leftOffset)?T=this.style.transformUnitToPx(e.position.leftOffset):O.test(e.position.leftOffset)&&(T=this.style.transformUnitToPx(e.position.leftOffset,b.width-P)),e.position.left===rt.left?T+=v.x:e.position.left===rt.right?T=b.width-P-T+v.x:e.position.left===rt.center&&(T+=b.width/2-P/2),x.test(e.position.topOffset)?E=this.style.transformUnitToPx(e.position.topOffset):O.test(e.position.topOffset)&&(E=this.style.transformUnitToPx(e.position.topOffset,b.height-k)),e.position.top===rt.top?E+=v.y:e.position.top===rt.bottom?E=b.height-k-E+v.y:e.position.top===rt.center&&(E+=b.height/2-k/2),e.gradient){var M=void 0;if(e.gradient.type===nt.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,s=e/2,l=i/2,a=Math.cos(n)*h,c=Math.sin(n)*h,d=t.createLinearGradient(s-a,l+c,s+a,l-c);return o.list.forEach((function(t,e){var i=t.stop;x.test(i)?i=(i=parseFloat(i)/r)>1?1:i:O.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&&a(t,i.gradient,M,P,k,T-b.x,E-b.y,b.x,b.y,b.width,b.height,e.repeat)}else m&&m.source&&a(t,i.image,m.source,P,k,T-b.x,E-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,s=this,a=s.offsetLeft,c=s.offsetTop,d=s.contentHeight,f=s.contentWidth,p=o.top,u=o.right,y=o.bottom,w=o.left,b=n.topLeft,v=n.topRight,T=n.bottomRight,x=n.bottomLeft,O=n.maxWidth,E=n.maxHeight,P=a+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===v.width&&0===v.height&&0===T.width&&0===T.height&&0===x.width&&0===x.height),M=!(0===p.width&&0===u.width&&0===y.width&&0===w.width),H=p.width===u.width&&u.width===y.width&&y.width===w.width&&w.width===p.width,R=p.color===u.color&&u.color===y.color&&y.color===w.color&&w.color===p.color,I=p.style===u.style&&u.style===y.style&&y.style===w.style&&w.style===p.style,S=b.width===O&&b.height===E&&v.width===O&&v.height===E&&T.width===O&&T.height===E&&x.width===O&&x.height===E,j=Math.PI/180,_=function(e){switch(e.style){case m.solid:t.setLineDash([]);break;case m.dashed:t.setLineDash([2*e.width,e.width])}},U=function(){t.beginPath(),b.width-w.width>0&&b.height-p.width>0?g(t,b.width,b.height,b.width-w.width,b.height-p.width,0,Math.PI,-90*j):t.moveTo(w.width,p.width),v.width-u.width>0&&v.height-p.width>0?g(t,N-v.width,v.height,v.width-u.width,v.height-p.width,0,-90*j,0):t.lineTo(N-u.width,p.width),T.width-u.width>0&&T.height-y.width>0?g(t,N-T.width,W-T.height,T.width-u.width,T.height-y.width,0,0,90*j):t.lineTo(N-u.width,W-y.width),x.width-w.width>0&&x.height-y.width>0?g(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()},D=function(){t.lineWidth=1,t.strokeStyle="transparent",t.stroke(),t.clip()};if(L){if(H&&I&&R&&S){if("function"==typeof e){t.save(),t.beginPath();var B=0;this.nodeName===l.img&&(B=p.width),g(t,N/2,W/2,N/2-B,W/2-B,0,0,2*Math.PI),D(),e(t),t.restore()}M&&(t.beginPath(),g(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?g(t,b.width,b.height,b.width,b.height,0,Math.PI,-90*j):t.moveTo(0,0),v.width>0&&v.height>0?g(t,N-v.width,v.height,v.width,v.height,0,-90*j,0):t.lineTo(N,0),T.width>0&&T.height>0?g(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?g(t,x.width,W-x.height,x.width,x.height,0,90*j,Math.PI):t.lineTo(0,W),t.closePath(),D(),M)if(H&&I&&R){if("function"==typeof