(function(m,h){"use strict";class w{constructor(){this.reset()}reset(){return this.stroke=0,this.strokeColor="#000000",this.leading=0,this.lineHeight=0,this.letterSpacing=0,this.href=null,this}recover(){this!=w.EMPTY&&h.Pool.recover("HTMLExtendStyle",this.reset())}static create(){return h.Pool.getItemByClass("HTMLExtendStyle",w)}}w.EMPTY=new w,h.ClassUtils.regClass("laya.html.utils.HTMLExtendStyle",w),h.ClassUtils.regClass("Laya.HTMLExtendStyle",w);class s{constructor(){this.padding=s._PADDING,this.reset()}_getExtendStyle(){return this._extendStyle===w.EMPTY&&(this._extendStyle=w.create()),this._extendStyle}get href(){return this._extendStyle.href}set href(t){t!==this._extendStyle.href&&(this._getExtendStyle().href=t)}get stroke(){return this._extendStyle.stroke}set stroke(t){this._extendStyle.stroke!==t&&(this._getExtendStyle().stroke=t)}get strokeColor(){return this._extendStyle.strokeColor}set strokeColor(t){this._extendStyle.strokeColor!==t&&(this._getExtendStyle().strokeColor=t)}get leading(){return this._extendStyle.leading}set leading(t){this._extendStyle.leading!==t&&(this._getExtendStyle().leading=t)}get lineHeight(){return this._extendStyle.lineHeight}set lineHeight(t){this._extendStyle.lineHeight!==t&&(this._getExtendStyle().lineHeight=t)}set align(t){t in s.alignVDic&&(this._type&=~s._ALIGN,this._type|=s.alignVDic[t])}get align(){var t=this._type&s._ALIGN;return s.align_Value[t]}set valign(t){t in s.alignVDic&&(this._type&=~s._VALIGN,this._type|=s.alignVDic[t])}get valign(){var t=this._type&s._VALIGN;return s.vAlign_Value[t]}set font(t){for(var e=t.split(" "),i=0,r=e.length;i0){this.fontSize=parseInt(n),this.family=e[i+1],i++;continue}}}get font(){return(this.italic?"italic ":"")+(this.bold?"bold ":"")+this.fontSize+"px "+(h.ILaya.Browser.onIPhone?h.ILaya.Text.fontFamilyMap[this.family]||this.family:this.family)}set block(t){t?this._type|=s._CSS_BLOCK:this._type&=~s._CSS_BLOCK}get block(){return(this._type&s._CSS_BLOCK)!=0}reset(){return this.ower=null,this._type=0,this.wordWrap=!0,this.fontSize=h.ILaya.Text.defaultFontSize,this.family=h.ILaya.Text.defaultFont,this.color="#000000",this.gradientColors=null,this.valign=s.VALIGN_TOP,this.padding=s._PADDING,this.bold=!1,this.italic=!1,this.align=s.ALIGN_LEFT,this.textDecoration=null,this.bgColor=null,this.borderColor=null,this._extendStyle&&this._extendStyle.recover(),this._extendStyle=w.EMPTY,this}recover(){h.Pool.recover("HTMLStyle",this.reset())}static create(){return h.Pool.getItemByClass("HTMLStyle",s)}inherit(t){var e,i,r;r=s._inheritProps,i=r.length;var n;for(e=0;e=0&&(this._type|=s._WIDTHAUTO,t=t.substr(0,e)),this._calculation("width",t))return;t=parseInt(t)}this.size(t,-1)}set height(t){if(this._type|=s._HEIGHT_SET,typeof t=="string"){if(this._calculation("height",t))return;t=parseInt(t)}this.size(-1,t)}heighted(t){return(this._type&s._HEIGHT_SET)!=0}size(t,e){var i=this.ower,r=!1;t!==-1&&t!=i.width&&(this._type|=s._WIDTH_SET,i.width=t,r=!0),e!==-1&&e!=i.height&&(this._type|=s._HEIGHT_SET,i.height=e,r=!0),r&&i._layoutLater()}getLineElement(){return(this._type&s._LINE_ELEMENT)!=0}setLineElement(t){t?this._type|=s._LINE_ELEMENT:this._type&=~s._LINE_ELEMENT}_enableLayout(){return(this._type&s._DISPLAY_NONE)===0&&(this._type&s._ABSOLUTE)===0}get letterSpacing(){return this._extendStyle.letterSpacing}set letterSpacing(t){typeof t=="string"&&(t=parseInt(t+"")),t!=this._extendStyle.letterSpacing&&(this._getExtendStyle().letterSpacing=t)}cssText(t){this.attrs(s.parseOneCSS(t,";"))}attrs(t){if(t)for(var e=0,i=t.length;e0});break;case"padding":n=p.split(" "),n.length>1||(n[1]=n[2]=n[3]=n[0]),g[1]=[parseInt(n[0]),parseInt(n[1]),parseInt(n[2]),parseInt(n[3])];break;default:(g[0]=s._CSSTOVALUE[_])||(g[0]=_)}i.push(g)}}return i}static parseCSS(t,e){for(var i;(i=s._parseCSSRegExp.exec(t))!=null;)s.styleSheets[i[1]]=s.parseOneCSS(i[2],";")}}s._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","gradient-colors":"gradientColors"},s._parseCSSRegExp=new RegExp("([.#]\\w+)\\s*{([\\s\\S]*?)}","g"),s._inheritProps=["italic","align","valign","leading","letterSpacing","stroke","strokeColor","bold","fontWeight","fontSize","lineHeight","wordWrap","color","gradientColors"],s.ALIGN_LEFT="left",s.ALIGN_CENTER="center",s.ALIGN_RIGHT="right",s.VALIGN_TOP="top",s.VALIGN_MIDDLE="middle",s.VALIGN_BOTTOM="bottom",s.styleSheets={},s.ADDLAYOUTED=512,s._PADDING=[0,0,0,0],s._HEIGHT_SET=8192,s._LINE_ELEMENT=65536,s._NOWARP=131072,s._WIDTHAUTO=262144,s._BOLD=1024,s._ITALIC=2048,s._CSS_BLOCK=1,s._DISPLAY_NONE=2,s._ABSOLUTE=4,s._WIDTH_SET=8,s.alignVDic={left:0,center:16,right:32,top:0,middle:64,bottom:128},s.align_Value={0:"left",16:"center",32:"right"},s.vAlign_Value={0:"top",64:"middle",128:"bottom"},s._ALIGN=48,s._VALIGN=192,h.ClassUtils.regClass("laya.html.utils.HTMLStyle",s),h.ClassUtils.regClass("Laya.HTMLStyle",s);class R{constructor(){this.all=[],this.styleSheets=s.styleSheets}getElementById(t){return this.all[t]}setElementById(t,e){this.all[t]=e}}R.document=new R,h.ClassUtils.regClass("laya.html.dom.HTMLDocument",R),h.ClassUtils.regClass("Laya.HTMLDocument",R);class k{constructor(){this.rec=new h.Rectangle,this.reset()}reset(){return this.rec.reset(),this.href=null,this}recover(){h.Pool.recover("HTMLHitRect",this.reset())}static create(){return h.Pool.getItemByClass("HTMLHitRect",k)}}h.ClassUtils.regClass("laya.html.dom.HTMLHitRect",k),h.ClassUtils.regClass("Laya.HTMLHitRect",k);class C{}C.HTMLDivElement=null,C.HTMLImageElement=null,C.HTMLBrElement=null,C.HTMLDivParser=null,C.HTMLParse=null,C.HTMLElementType=null;class W{constructor(){this.elements=[],this.x=0,this.y=0,this.w=0,this.h=0,this.wordStartIndex=0,this.minTextHeight=99999,this.mWidth=0}updatePos(t,e,i,r,n,a,l){var d=0,o;this.elements.length>0&&(o=this.elements[this.elements.length-1],d=o.x+o.width-this.elements[0].x),l=l||this.h;var _=0,p;n===s.ALIGN_CENTER&&(_=(e-d)/2),n===s.ALIGN_RIGHT&&(_=e-d);for(var g=0,x=this.elements.length;g0&&b+D.width+D.style.letterSpacing>_&&u.wordStartIndex>0){var Z=0;Z=u.elements.length-u.wordStartIndex+1,u.elements.length=u.wordStartIndex,i-=Z,z();continue}A=!1,q+=D.width}V=D.width+D.style.letterSpacing,K=D.height,X=!1,A=A||b+V>_,A&&z(),u.minTextHeight=Math.min(u.minTextHeight,E.height)}else B=E._getCSSStyle(),$=E,F=B.padding,A=X||B.getLineElement(),V=$.width+F[1]+F[3]+B.letterSpacing,K=$.height+F[0]+F[2],X=B.getLineElement(),A=A||b+V>_&&B.wordWrap,A&&z();u.elements.push(E),u.h=Math.max(u.h,K),E.x=b,E.y=L,b+=V,u.w=b-a,u.y=L,g=Math.max(b+x,g)}if(L=u.y+u.h,U){var Q=0,j=_;for(o&&t.width>0&&(j=t.width),i=0,r=H.length;it.height&&(t.height=L),[g,L]}}y.DIV_ELEMENT_PADDING=0,h.ClassUtils.regClass("laya.html.utils.Layout",y),h.ClassUtils.regClass("Laya.Layout",y),function(I){I[I.BASE=0]="BASE",I[I.IMAGE=1]="IMAGE"}(m.HTMLElementType||(m.HTMLElementType={}));class f{constructor(){this.eletype=m.HTMLElementType.BASE,this._creates(),this.reset()}static formatURL1(t,e=null){if(!t)return"null path";if(e||(e=h.URL.basePath),t.indexOf(":")>0||(h.URL.customFormat!=null&&(t=h.URL.customFormat(t)),t.indexOf(":")>0))return t;var i=t.charAt(0);if(i===".")return h.URL._formatRelativePath(e+t);if(i==="~")return h.URL.rootPath+t.substring(1);if(i==="d"){if(t.indexOf("data:image")===0)return t}else if(i==="/")return t;return e+t}_creates(){this._style=s.create()}reset(){if(this.URI=null,this.parent=null,this._style.reset(),this._style.ower=this,this._style.valign="middle",this._text&&this._text.words){var t=this._text.words,e,i;i=t.length;var r;for(e=0;e-1;t--)this._children[t].destroy();this._children.length=0}}get style(){return this._style}_getWords(){if(!this._text)return null;var t=this._text.text;if(!t||t.length===0)return null;var e=this._text.words;if(e&&e.length===t.length)return e;e===null&&(this._text.words=e=[]),e.length=t.length;for(var i,r=this.style,n=r.font,a=0,l=t.length;a0||this._getWords()!=null)&&t.block?(y.later(this),t._type|=s.ADDLAYOUTED):this.parent&&this.parent._layoutLater())}set x(t){this._x!=t&&(this._x=t,this.parentRepaint())}get x(){return this._x}set y(t){this._y!=t&&(this._y=t,this.parentRepaint())}get y(){return this._y}get width(){return this._width}set width(t){this._width!==t&&(this._width=t,this.repaint())}get height(){return this._height}set height(t){this._height!==t&&(this._height=t,this.repaint())}_setAttributes(t,e){switch(t){case"style":this.style.cssText(e);break;case"class":this.className=e;break;case"x":this.x=parseFloat(e);break;case"y":this.y=parseFloat(e);break;case"width":this.width=parseFloat(e);break;case"height":this.height=parseFloat(e);break;default:this[t]=e}}set href(t){this._style&&t!=this._style.href&&(this._style.href=t,this.repaint())}get href(){return this._style?this._style.href:null}formatURL(t){return this.URI?f.formatURL1(t,this.URI?this.URI.path:null):t}set color(t){this.style.color=t}set className(t){this.style.attrs(R.document.styleSheets["."+t])}getGradientColors(){if(this.style.gradientColors&&this.style.gradientColors.length>=2)return this.style.gradientColors;if(this._children)for(var t=0;t0)for(d=this._children.length,l=0;l=2)for(var a=r.stroke&&parseInt(r.stroke)||0,l=0;l=2)for(var a=0;a/g,"
"),e=""+e+"",e=e.replace(c.spacePattern,c.char255);var r=h.Utils.parseXMLFromString(e);c._parseXML(t,r.childNodes[0].childNodes,i)}static normalizeText(t){if(!t)return"";var e=t.charAt(0),i=t.charAt(t.length-1),r=e===" "||e===c.char255,n=i===" "||i===c.char255;return t=t.replace(c.char255AndOneSpacePattern," "),t.replace(c.edgeBlankPattern,"").length===0?"":(t=t.replace(c.edgeBlankPattern,""),r&&(t=" "+t),n&&(t+=" "),t)}static _parseXML(t,e,i,r=null){var n,a;if(e.join||e.item)for(n=0,a=e.length;n0&&(l=c.getInstance(d),l&&(l._style&&(l._style.family=t.style.family),t.addChild(l),l.innerTEXT=o));else if(o=c.normalizeText(e.textContent),o.length>0){var _=t;if(t instanceof f&&t.innerTEXT&&t.innerTEXT.length>0){let v=c.getInstance("p");v&&(v._style&&(v._style.family=t.style.family),t.addChild(v),_=v)}_.innerTEXT=o}return}else{if(d=e.nodeName.toLowerCase(),d=="#comment")return;if(l=c.getInstance(d),l){l._style&&(l._style.family=t.style.family),d=="p"?(t.addChild(c.getInstance("br")),l=t.addChild(l),t.addChild(c.getInstance("br"))):l=t.addChild(l),l.URI=i,l.href=r;var p=e.attributes;if(p&&p.length>0)for(n=0,a=p.length;n0&&this._setGraphicDirty()}_updateGraphicWork(){switch(this._repaintState){case 1:this._updateGraphic();break;case 2:this._refresh();break}}_setGraphicDirty(){this.callLater(this._updateGraphicWork)}_doClears(){if(this._recList){var t,e=this._recList.length,i;for(t=0;t>16&255,e>>8&255,e&255]}get style(){return this._element.style}set innerHTML(t){this._innerHTML!=t&&(this._repaintState=1,this._innerHTML=t,this._element.innerHTML=t,this._setGraphicDirty(),this.event(h.Event.CHANGE))}_refresh(){this._repaintState=1,this._innerHTML&&(this._element.innerHTML=this._innerHTML),this._setGraphicDirty()}get contextWidth(){return this._element.contextWidth}get contextHeight(){return this._element.contextHeight}_onMouseClick(){var t=this.mouseX,e=this.mouseY,i,r,n;for(r=this._recList.length,i=0;i{var r=this._element.URI;this._element.URI=new h.URL(t),this.innerHTML=i,!r||(this._element.URI=r)}),e.load(t,h.Loader.TEXT)}}h.ClassUtils.regClass("laya.html.dom.HTMLIframeElement",Y),h.ClassUtils.regClass("Laya.HTMLIframeElement",Y),m.HTMLBrElement=T,m.HTMLDivElement=S,m.HTMLDivParser=G,m.HTMLDocument=R,m.HTMLElement=f,m.HTMLExtendStyle=w,m.HTMLHitRect=k,m.HTMLIframeElement=Y,m.HTMLImageElement=M,m.HTMLLinkElement=O,m.HTMLParse=c,m.HTMLStyle=s,m.HTMLStyleElement=P,m.IHtml=C,m.Layout=y,m.LayoutLine=W})(Laya,Laya);