!function(window,document,Laya){Laya.un,Laya.uns;var __static=Laya.static,__class=Laya.class,__getset=Laya.getset,Browser=(Laya.__newvec,laya.utils.Browser),ClassUtils=laya.utils.ClassUtils,HTMLChar=(laya.resource.Context,laya.events.Event,laya.display.Graphics,laya.utils.HTMLChar),Handler=laya.utils.Handler,Loader=laya.net.Loader,Pool=laya.utils.Pool,Rectangle=laya.maths.Rectangle,Sprite=laya.display.Sprite,Text=laya.display.Text,Texture=laya.resource.Texture,URL=laya.net.URL,Utils=laya.utils.Utils;Laya.interface("laya.html.utils.ILayout");var HTMLHitRect=function(){function HTMLHitRect(){this.rec=new Rectangle,this.reset()}__class(HTMLHitRect,"laya.html.dom.HTMLHitRect");var __proto=HTMLHitRect.prototype;return __proto.reset=function(){return this.rec.reset(),this.href=null,this},__proto.recover=function(){Pool.recover("HTMLHitRect",this.reset())},HTMLHitRect.create=function(){return Pool.getItemByClass("HTMLHitRect",HTMLHitRect)},HTMLHitRect}(),LayoutLine=function(){function LayoutLine(){this.x=0,this.y=0,this.w=0,this.h=0,this.wordStartIndex=0,this.minTextHeight=99999,this.mWidth=0,this.elements=new Array}return __class(LayoutLine,"laya.html.utils.LayoutLine"),LayoutLine.prototype.updatePos=function(left,width,lineNum,dy,align,valign,lineHeight){var one,w=0;this.elements.length>0&&(w=(one=this.elements[this.elements.length-1]).x+one.width-this.elements[0].x),lineHeight=lineHeight||this.h;var dx=0,ddy=NaN;"center"===align&&(dx=(width-w)/2),"right"===align&&(dx=width-w);for(var i=0,n=this.elements.length;i0&&x+w>width&&curLine.wordStartIndex>0){var tLineWord;tLineWord=curLine.elements.length-curLine.wordStartIndex+1,curLine.elements.length=curLine.wordStartIndex,i-=tLineWord,addLine();continue}newLine=!1,tWordWidth+=htmlWord.width}w=htmlWord.width+htmlWord.style.letterSpacing,h=htmlWord.height,nextNewline=!1,(newLine=newLine||x+w>width)&&addLine(),curLine.minTextHeight=Math.min(curLine.minTextHeight,oneLayout.height)}else curStyle=oneLayout._getCSSStyle(),sprite=oneLayout,curPadding=curStyle.padding,newLine=nextNewline||curStyle.getLineElement(),w=sprite.width+curPadding[1]+curPadding[3]+curStyle.letterSpacing,h=sprite.height+curPadding[0]+curPadding[2],nextNewline=curStyle.getLineElement(),(newLine=newLine||x+w>width&&curStyle.wordWrap)&&addLine();curLine.elements.push(oneLayout),curLine.h=Math.max(curLine.h,h),oneLayout.x=x,oneLayout.y=y,x+=w,curLine.w=x-letterSpacing,curLine.y=y,maxWidth=Math.max(x+exWidth,maxWidth)}else tLineFirstKey||(x+=Layout.DIV_ELEMENT_PADDING),curLine.wordStartIndex=curLine.elements.length;if(y=curLine.y+curLine.h,endAdjust){var tY=0,tWidth=width;for(widthAuto&&element.width>0&&(tWidth=element.width),i=0,n=lines.length;ielement.height&&(element.height=y),[maxWidth,y]},Layout.DIV_ELEMENT_PADDING=0,Layout._will=null,Layout}(),HTMLStyle=(function(){function HTMLBrElement(){}__class(HTMLBrElement,"laya.html.dom.HTMLBrElement");var __proto=HTMLBrElement.prototype;__proto._addToLayout=function(out){out.push(this)},__proto.reset=function(){return this},__proto.destroy=function(){Pool.recover(HTMLElement.getClassName(this),this.reset())},__proto._setParent=function(value){},__proto._getCSSStyle=function(){return HTMLBrElement.brStyle||(HTMLBrElement.brStyle=new HTMLStyle,HTMLBrElement.brStyle.setLineElement(!0),HTMLBrElement.brStyle.block=!0),HTMLBrElement.brStyle},__proto.renderSelfToGraphic=function(graphic,gX,gY,recList){},__getset(0,__proto,"URI",null,function(value){}),__getset(0,__proto,"parent",null,function(value){}),__getset(0,__proto,"href",null,function(value){}),HTMLBrElement.brStyle=null}(),function(){function HTMLStyle(){this.padding=HTMLStyle._PADDING,this.reset()}__class(HTMLStyle,"laya.html.utils.HTMLStyle");var __proto=HTMLStyle.prototype;return __proto._getExtendStyle=function(){return this._extendStyle===HTMLExtendStyle.EMPTY&&(this._extendStyle=HTMLExtendStyle.create()),this._extendStyle},__proto.reset=function(){return this.ower=null,this._type=0,this.wordWrap=!0,this.fontSize=Text.defaultFontSize,this.family=Text.defaultFont,this.color="#000000",this.valign="top",this.padding=HTMLStyle._PADDING,this.bold=!1,this.italic=!1,this.align="left",this.textDecoration=null,this.bgColor=null,this.borderColor=null,this._extendStyle&&this._extendStyle.recover(),this._extendStyle=HTMLExtendStyle.EMPTY,this},__proto.recover=function(){Pool.recover("HTMLStyle",this.reset())},__proto.inherit=function(src){var len,props,key,i=0;for(len=(props=HTMLStyle._inheritProps).length,i=0;i0&&(this.fontSize=parseInt(str),this.family=strs[i+1],i++)}}),__getset(0,__proto,"href",function(){return this._extendStyle.href},function(value){value!==this._extendStyle.href&&(this._getExtendStyle().href=value)}),__getset(0,__proto,"lineHeight",function(){return this._extendStyle.lineHeight},function(value){this._extendStyle.lineHeight!==value&&(this._getExtendStyle().lineHeight=value)}),__getset(0,__proto,"strokeColor",function(){return this._extendStyle.strokeColor},function(value){this._extendStyle.strokeColor!==value&&(this._getExtendStyle().strokeColor=value)}),__getset(0,__proto,"stroke",function(){return this._extendStyle.stroke},function(value){this._extendStyle.stroke!==value&&(this._getExtendStyle().stroke=value)}),__getset(0,__proto,"leading",function(){return this._extendStyle.leading},function(value){this._extendStyle.leading!==value&&(this._getExtendStyle().leading=value)}),__getset(0,__proto,"align",function(){var v=48&this._type;return HTMLStyle.align_Value[v]},function(v){v in HTMLStyle.alignVDic&&(this._type&=-49,this._type|=HTMLStyle.alignVDic[v])}),__getset(0,__proto,"valign",function(){var v=192&this._type;return HTMLStyle.vAlign_Value[v]},function(v){v in HTMLStyle.alignVDic&&(this._type&=-193,this._type|=HTMLStyle.alignVDic[v])}),__getset(0,__proto,"block",function(){return 0!=(1&this._type)},function(value){value?this._type|=1:this._type&=-2}),__getset(0,__proto,"wordWrap",function(){return 0==(131072&this._type)},function(value){value?this._type&=-131073:this._type|=131072}),__getset(0,__proto,"bold",function(){return 0!=(1024&this._type)},function(value){value?this._type|=1024:this._type&=-1025}),__getset(0,__proto,"italic",function(){return 0!=(2048&this._type)},function(value){value?this._type|=2048:this._type&=-2049}),__getset(0,__proto,"whiteSpace",function(){return 131072&this._type?"nowrap":""},function(type){"nowrap"===type&&(this._type|=131072),"none"===type&&(this._type&=-131073)}),__getset(0,__proto,"width",null,function(w){if(this._type|=8,"string"==typeof w){var offset=w.indexOf("auto");if(offset>=0&&(this._type|=262144,w=w.substr(0,offset)),this._calculation("width",w))return;w=parseInt(w)}this.size(w,-1)}),__getset(0,__proto,"height",null,function(h){if(this._type|=8192,"string"==typeof h){if(this._calculation("height",h))return;h=parseInt(h)}this.size(-1,h)}),__getset(0,__proto,"letterSpacing",function(){return this._extendStyle.letterSpacing},function(d){"string"==typeof d&&(d=parseInt(d+"")),d!=this._extendStyle.letterSpacing&&(this._getExtendStyle().letterSpacing=d)}),__getset(0,__proto,"position",function(){return 4&this._type?"absolute":""},function(value){"absolute"===value?this._type|=4:this._type&=-5}),__getset(0,__proto,"absolute",function(){return 0!=(4&this._type)}),__getset(0,__proto,"paddingLeft",function(){return this.padding[3]}),__getset(0,__proto,"paddingTop",function(){return this.padding[0]}),HTMLStyle.create=function(){return Pool.getItemByClass("HTMLStyle",HTMLStyle)},HTMLStyle.parseOneCSS=function(text,clipWord){for(var valueArray,out=[],attrs=text.split(clipWord),i=0,n=attrs.length;i1||(valueArray[1]=valueArray[2]=valueArray[3]=valueArray[0]),one[1]=[parseInt(valueArray[0]),parseInt(valueArray[1]),parseInt(valueArray[2]),parseInt(valueArray[3])];break;default:(one[0]=HTMLStyle._CSSTOVALUE[name])||(one[0]=name)}out.push(one)}}return out},HTMLStyle.parseCSS=function(text,uri){for(var one;null!=(one=HTMLStyle._parseCSSRegExp.exec(text));)HTMLStyle.styleSheets[one[1]]=HTMLStyle.parseOneCSS(one[2],";")},HTMLStyle._CSSTOVALUE={"letter-spacing":"letterSpacing","white-space":"whiteSpace","line-height":"lineHeight","font-family":"family","vertical-align":"valign","text-decoration":"textDecoration","background-color":"bgColor","border-color":"borderColor"},HTMLStyle._parseCSSRegExp=new RegExp("([.#]\\w+)\\s*{([\\s\\S]*?)}","g"),HTMLStyle.ALIGN_LEFT="left",HTMLStyle.ALIGN_CENTER="center",HTMLStyle.ALIGN_RIGHT="right",HTMLStyle.VALIGN_TOP="top",HTMLStyle.VALIGN_MIDDLE="middle",HTMLStyle.VALIGN_BOTTOM="bottom",HTMLStyle.styleSheets={},HTMLStyle.ADDLAYOUTED=512,HTMLStyle._PADDING=[0,0,0,0],HTMLStyle._HEIGHT_SET=8192,HTMLStyle._LINE_ELEMENT=65536,HTMLStyle._NOWARP=131072,HTMLStyle._WIDTHAUTO=262144,HTMLStyle._BOLD=1024,HTMLStyle._ITALIC=2048,HTMLStyle._CSS_BLOCK=1,HTMLStyle._DISPLAY_NONE=2,HTMLStyle._ABSOLUTE=4,HTMLStyle._WIDTH_SET=8,HTMLStyle._ALIGN=48,HTMLStyle._VALIGN=192,__static(HTMLStyle,["_inheritProps",function(){return this._inheritProps=["italic","align","valign","leading","stroke","strokeColor","bold","fontSize","lineHeight","wordWrap","color"]},"alignVDic",function(){return this.alignVDic={left:0,center:16,right:32,top:0,middle:64,bottom:128}},"align_Value",function(){return this.align_Value={0:"left",16:"center",32:"right"}},"vAlign_Value",function(){return this.vAlign_Value={0:"top",64:"middle",128:"bottom"}}]),HTMLStyle}()),HTMLExtendStyle=function(){function HTMLExtendStyle(){this.reset()}__class(HTMLExtendStyle,"laya.html.utils.HTMLExtendStyle");var __proto=HTMLExtendStyle.prototype;return __proto.reset=function(){return this.stroke=0,this.strokeColor="#000000",this.leading=0,this.lineHeight=0,this.letterSpacing=0,this.href=null,this},__proto.recover=function(){this!=HTMLExtendStyle.EMPTY&&Pool.recover("HTMLExtendStyle",this.reset())},HTMLExtendStyle.create=function(){return Pool.getItemByClass("HTMLExtendStyle",HTMLExtendStyle)},HTMLExtendStyle.EMPTY=new HTMLExtendStyle,HTMLExtendStyle}(),HTMLElement=function(){function HTMLElement(){this._creates(),this.reset()}__class(HTMLElement,"laya.html.dom.HTMLElement");var __proto=HTMLElement.prototype;return __proto._creates=function(){this._style=HTMLStyle.create()},__proto.reset=function(){if(this.URI=null,this.parent=null,this._style.reset(),this._style.ower=this,this._style.valign="middle",this._text&&this._text.words){var len,tChar,words=this._text.words,i=0;for(len=words.length,i=0;i-1;i--)this._children[i].destroy();this._children.length=0}},__proto._getWords=function(){if(!this._text)return null;var txt=this._text.text;if(!txt||0===txt.length)return null;var size,words=this._text.words;if(words&&words.length===txt.length)return words;null===words&&(this._text.words=words=[]),words.length=txt.length;for(var style=this.style,fontStr=style.font,i=0,n=txt.length;i0||null!=this._getWords())&&style.block?(Layout.later(this),style._type|=512):this.parent&&this.parent._layoutLater())},__proto._setAttributes=function(name,value){switch(name){case"style":this.style.cssText(value);break;case"class":this.className=value;break;case"x":this.x=parseFloat(value);break;case"y":this.y=parseFloat(value);break;case"width":this.width=parseFloat(value);break;case"height":this.height=parseFloat(value);break;default:this[name]=value}},__proto.formatURL=function(url){return this.URI?HTMLElement.formatURL1(url,this.URI?this.URI.path:null):url},__proto.drawToGraphic=function(graphic,gX,gY,recList){gX+=this.x,gY+=this.y;var cssStyle=this.style;cssStyle.paddingLeft&&(gX+=cssStyle.paddingLeft),cssStyle.paddingTop&&(gY+=cssStyle.paddingTop),(null!=cssStyle.bgColor||cssStyle.borderColor)&&graphic.drawRect(gX,gY,this.width,this.height,cssStyle.bgColor,cssStyle.borderColor,1),this.renderSelfToGraphic(graphic,gX,gY,recList);var tChild,i=0,len=0;if(this._children&&this._children.length>0)for(len=this._children.length,i=0;i0)return url;if(null!=URL.customFormat&&(url=URL.customFormat(url)),url.indexOf(":")>0)return url;var char1=url.charAt(0);if("."===char1)return URL._formatRelativePath(basePath+url);if("~"===char1)return URL.rootPath+url.substring(1);if("d"===char1){if(0===url.indexOf("data:image"))return url}else if("/"===char1)return url;return basePath+url},HTMLElement.getClassName=function(tar){return"function"==typeof tar?tar.name:tar.constructor.name},HTMLElement._EMPTYTEXT={text:null,words:null},HTMLElement}(),HTMLParse=function(){function HTMLParse(){}return __class(HTMLParse,"laya.html.utils.HTMLParse"),HTMLParse.getInstance=function(type){var rst=Pool.getItem(HTMLParse._htmlClassMapShort[type]);return rst||(rst=ClassUtils.getInstance(type)),rst},HTMLParse.parse=function(ower,xmlString,url){xmlString=(xmlString=""+(xmlString=xmlString.replace(/
/g,"
"))+"
").replace(HTMLParse.spacePattern,HTMLParse.char255);var xml=Utils.parseXMLFromString(xmlString);HTMLParse._parseXML(ower,xml.childNodes[0].childNodes,url)},HTMLParse._parseXML=function(parent,xml,url,href){var i=0,n=0;if(xml.join||xml.item)for(i=0,n=xml.length;i0&&(node=HTMLParse.getInstance(nodeName))&&(parent.addChild(node),node.innerTEXT=txt.replace(HTMLParse.char255AndOneSpacePattern," "))):(txt=xml.textContent.replace(/^\s+|\s+$/g,"")).length>0&&(parent.innerTEXT=txt.replace(HTMLParse.char255AndOneSpacePattern," ")));if("#comment"==(nodeName=xml.nodeName.toLowerCase()))return;if(node=HTMLParse.getInstance(nodeName)){"p"==nodeName?(parent.addChild(HTMLParse.getInstance("br")),node=parent.addChild(node),parent.addChild(HTMLParse.getInstance("br"))):node=parent.addChild(node),node.URI=url,node.href=href;var attributes=xml.attributes;if(attributes&&attributes.length>0)for(i=0,n=attributes.length;i0&&this._setGraphicDirty()},__proto._updateGraphicWork=function(){switch(this._repaintState){case 1:this._updateGraphic();break;case 2:this._refresh()}},__proto._setGraphicDirty=function(){this.callLater(this._updateGraphicWork)},__proto._doClears=function(){if(this._recList){var i=0,len=this._recList.length;for(i=0;i