mirror of
https://github.com/VickScarlet/lifeRestart.git
synced 2025-07-16 17:13:52 +08:00
1 line
14 KiB
JavaScript
1 line
14 KiB
JavaScript
!function(n){n.un,n.uns;var i=n.static,h=n.class,l=n.getset,s=(n.__newvec,laya.utils.Browser,laya.display.css.CSSStyle),c=laya.utils.ClassUtils,d=(laya.events.Event,laya.utils.HTMLChar),r=laya.net.Loader,a=(laya.display.Node,laya.maths.Rectangle),o=laya.renders.Render,u=(laya.renders.RenderContext,laya.renders.RenderSprite,laya.display.Sprite),_=laya.utils.Stat,R=laya.display.Text,f=laya.resource.Texture,y=laya.net.URL,g=laya.utils.Utils,p=(h(m,"laya.html.utils.HTMLParse"),m.parse=function(t,e,i){e=(e="<root>"+(e=e.replace(/<br>/g,"<br/>"))+"</root>").replace(m.spacePattern,m.char255);e=g.parseXMLFromString(e);m._parseXML(t,e.childNodes[0].childNodes,i)},m._parseXML=function(t,e,i,n){var h,l,s,r=0,a=0;if(e.join||e.item)for(r=0,a=e.length;r<a;++r)m._parseXML(t,e[r],i,n);else if(3==e.nodeType)t instanceof laya.html.dom.HTMLDivElement?(null==e.nodeName&&(e.nodeName="#text"),l=e.nodeName.toLowerCase(),0<(s=e.textContent.replace(/^\s+|\s+$/g,"")).length&&(h=c.getInstance(l))&&(t.addChild(h),h.innerTEXT=s.replace(m.char255AndOneSpacePattern," "))):0<(s=e.textContent.replace(/^\s+|\s+$/g,"")).length&&(t.innerTEXT=s.replace(m.char255AndOneSpacePattern," "));else if("#comment"!=(l=e.nodeName.toLowerCase()))if(h=c.getInstance(l)){(h=t.addChild(h)).URI=i,h.href=n;var o=e.attributes;if(o&&0<o.length)for(r=0,a=o.length;r<a;++r){var d=o[r],u=d.nodeName,d=d.value;h._setAttributes(u,d)}m._parseXML(h,e.childNodes,i,h.href)}else m._parseXML(t,e.childNodes,i,n)},m.char255=String.fromCharCode(255),m.spacePattern=/ | /g,m.char255AndOneSpacePattern=new RegExp(String.fromCharCode(255)+"|(\\s+)","g"),m);function m(){}var w=(h(W,"laya.html.utils.Layout"),W.later=function(t){null==W._will&&(W._will=[],n.stage.frameLoop(1,null,function(){if(!(W._will.length<1)){for(var t=0;t<W._will.length;t++)laya.html.utils.Layout.layout(W._will[t]);W._will.length=0}})),W._will.push(t)},W.layout=function(t){if(!t||!t._style)return null;if(0==(512&t._style._type))return null;t.getStyle()._type&=-513;var e=W._multiLineLayout(t);return o.isConchApp&&t.layaoutCallNative&&t.layaoutCallNative(),e},W._multiLineLayout=function(t){if(R.RightToLeft)return W._multiLineLayout2(t);var e=new Array;t._addChildsToLayout(e);var i,n,h,l=0,s=e.length,r=t._getCSSStyle(),a=r.letterSpacing,o=r.leading,d=r.lineHeight,u=r._widthAuto()||!r.wordWrap,c=u?999999:t.width,_=(t.height,0),f=r.italic?r.fontSize/3:0,y=r._getAlign(),g=r._getValign(),p=0!==g||0!==y||0!=d,m=0,w=0,x=0,v=0,S=new Array,L=S[0]=new U,T=!1,C=!1;L.h=0,r.italic&&(c-=r.fontSize/3);var E=0,M=!0;function H(){L.y=w,w+=L.h+o,0==L.h&&(w+=d),L.mWidth=E,E=0,L=new U,S.push(L),L.h=0,T=!(M=!(m=0))}for(l=0;l<s;l++)if(null!=(i=e[l]))if(M=!1,i instanceof laya.html.dom.HTMLBrElement)H(),L.y=w;else{if(i._isChar()){if((h=i).isWord)T=C||"\n"===h.char,L.wordStartIndex=L.elements.length;else{if(0<S.length&&c<m+x&&0<L.wordStartIndex){var I=L.elements.length-L.wordStartIndex+1;L.elements.length=L.wordStartIndex,l-=I,H();continue}T=!1,E+=h.width}x=h.width+a,v=h.height,C=!1,(T=T||c<m+x)&&H(),L.minTextHeight=Math.min(L.minTextHeight,i.height)}else n=i._getCSSStyle(),I=i,h=n.padding,0===n._getCssFloat()||(p=!0),T=C||n.lineElement,x=I.width*I._style._tf.scaleX+h[1]+h[3]+a,v=I.height*I._style._tf.scaleY+h[0]+h[2],C=n.lineElement,(T=T||c<m+x&&n.wordWrap)&&H();L.elements.push(i),L.h=Math.max(L.h,v),i.x=m,i.y=w,m+=x,L.w=m-a,L.y=w,_=Math.max(m+f,_)}else M||(m+=W.DIV_ELEMENT_PADDING),L.wordStartIndex=L.elements.length;if(w=L.y+L.h,p){var A=0,N=c;for(u&&0<t.width&&(N=t.width),l=0,s=S.length;l<s;l++)S[l].updatePos(0,N,l,A,y,g,d),A+=Math.max(d,S[l].h+o);w=A}return u&&(t.width=_),w>t.height&&(t.height=w),[_,w]},W._multiLineLayout2=function(t){var e=new Array;t._addChildsToLayout(e);var i,n,h,l=0,s=e.length,r=t._getCSSStyle(),a=r.letterSpacing,o=r.leading,d=r.lineHeight,u=r._widthAuto()||!r.wordWrap,c=u?999999:t.width,_=(t.height,0),f=r.italic?r.fontSize/3:0,y=2-r._getAlign(),g=r._getValign(),p=0!==g||0!=y||0!=d,m=0,w=0,x=0,v=0,S=new Array,L=S[0]=new U,T=!1,C=!1;L.h=0,r.italic&&(c-=r.fontSize/3);var E=0,M=!0;function H(){L.y=w,w+=L.h+o,0==L.h&&(w+=d),L.mWidth=E,E=0,L=new U,S.push(L),L.h=0,T=!(M=!(m=0))}for(l=0;l<s;l++)if(null!=(i=e[l]))if(M=!1,i instanceof laya.html.dom.HTMLBrElement)H(),L.y=w;else{if(i._isChar()){if((h=i).isWord)T=C||"\n"===h.char,L.wordStartIndex=L.elements.length;else{if(0<S.length&&c<m+x&&0<L.wordStartIndex){var I=L.elements.length-L.wordStartIndex+1;L.elements.length=L.wordStartIndex,l-=I,H();continue}T=!1,E+=h.width}x=h.width+a,v=h.height,C=!1,(T=T||c<m+x)&&H(),L.minTextHeight=Math.min(L.minTextHeight,i.height)}else n=i._getCSSStyle(),I=i,h=n.padding,0===n._getCssFloat()||(p=!0),T=C||n.lineElement,x=I.width*I._style._tf.scaleX+h[1]+h[3]+a,v=I.height*I._style._tf.scaleY+h[0]+h[2],C=n.lineElement,(T=T||c<m+x&&n.wordWrap)&&H();L.elements.push(i),L.h=Math.max(L.h,v),i.x=m,i.y=w,m+=x,L.w=m-a,L.y=w,_=Math.max(m+f,_)}else M||(m+=W.DIV_ELEMENT_PADDING),L.wordStartIndex=L.elements.length;if(w=L.y+L.h,p){for(var A=0,N=c,l=0,s=S.length;l<s;l++)S[l].updatePos(0,N,l,A,y,g,d),A+=Math.max(d,S[l].h+o);w=A}for(u&&(t.width=_),w>t.height&&(t.height=w),l=0,s=S.length;l<s;l++)S[l].revertOrder(c);return[_,w]},W._will=null,W.DIV_ELEMENT_PADDING=0,W);function W(){}var U=function(){function t(){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}h(t,"laya.html.utils.LayoutLine");var e=t.prototype;return e.updatePos=function(t,e,i,n,h,l,s){var r=0;0<this.elements.length&&(r=(c=this.elements[this.elements.length-1]).x+c.width-this.elements[0].x);var a=0,o=NaN;1===h&&(a=(e-r)/2),2===h&&(a=e-r),0===s||0!=l||(l=1);for(var d=0,u=this.elements.length;d<u;d++){var c,_=(c=this.elements[d])._getCSSStyle();switch(0!==a&&(c.x+=a),_._getValign()){case 0:c.y=n;break;case 1:var f=0,f=((f=99999!=this.minTextHeight?this.minTextHeight:f)+s)/2,f=Math.max(f,this.h),o=(laya.html.dom.HTMLImageElement,n+f-c.height);c.y=o;break;case 2:c.y=n+(s-c.height)}}},e.revertOrder=function(t){var e;if(0<this.elements.length)for(var i=0,n=this.elements.length,i=0;i<n;i++)(e=this.elements[i]).x=t-e.x-e.width},t}(),x=function(i){function e(){this.URI=null,this._href=null,e.__super.call(this),this._text=e._EMPTYTEXT,this.setStyle(new s(this)),this._getCSSStyle().valign="middle",this.mouseEnabled=!0}h(e,"laya.html.dom.HTMLElement",i);var t=e.prototype;return t.layaoutCallNative=function(){var t=0;if(this._childs&&0<(t=this._childs.length))for(var e=0;e<t;e++)this._childs[e].layaoutCallNative&&this._childs[e].layaoutCallNative();var i=this._getWords();i?laya.html.dom.HTMLElement.fillWords(this,i,0,0,this.style.font,this.style.color,this.style.underLine,this.style.stroke,this.style.strokeColor):this.graphics.clear()},t.appendChild=function(t){return this.addChild(t)},t._getWords2=function(){var t=this._text.text;if(!t||0===t.length)return null;var e,i,n=0,h=0;if(this._text.drawWords)i=this._text.drawWords;else{for(h=(e=t.split(" ")).length-1,i=[],n=0;n<h;n++)i.push(e[n]," ");0<=h&&i.push(e[h]),this._text.drawWords=i}var l=this._text.words;if(l&&l.length===i.length)return l;null===l&&(this._text.words=l=[]),l.length=i.length;for(var s=this.style,r=s.font,n=0,h=i.length;n<h;n++){var a=g.measureText(i[n],r),o=l[n]=new d(i[n],a.width,a.height||s.fontSize,s);1<o.char.length&&(o.charNum=o.char),this.href&&(a=new u,this.addChild(a),o.setSprite(a))}return l},t._getWords=function(){if(!R.CharacterCache)return this._getWords2();var t=this._text.text;if(!t||0===t.length)return null;var e=this._text.words;if(e&&e.length===t.length)return e;null===e&&(this._text.words=e=[]),e.length=t.length;for(var i=this.style,n=i.font,h=0,l=t.length;h<l;h++){var s=g.measureText(t.charAt(h),n),r=e[h]=new d(t.charAt(h),s.width,s.height||i.fontSize,i);this.href&&(s=new u,this.addChild(s),r.setSprite(s))}return e},t.showLinkSprite=function(){var t=this._text.words;if(t)for(var e,i,n=[],h=0;h<t.length;h++)i=t[h],(e=new u).graphics.drawRect(0,0,i.width,i.height,"#ff0000"),e.width=i.width,e.height=i.height,this.addChild(e),n.push(e)},t._layoutLater=function(){var t=this.style;512&t._type||(t.widthed(this)&&(0<this._childs.length||null!=this._getWords())&&t.block?(w.later(this),t._type|=512):this.parent&&this.parent._layoutLater())},t._setAttributes=function(t,e){switch(t){case"style":return void this.style.cssText(e);case"class":return void(this.className=e)}i.prototype._setAttributes.call(this,t,e)},t.updateHref=function(){if(null!=this._href){var t=this._getWords();if(t)for(var e,i,n=0;n<t.length;n++)(i=(e=t[n]).getSprite())&&(i.size(e.width,e.height),i.on("click",this,this.onLinkHandler))}},t.onLinkHandler=function(t){if("click"===t.type)for(var e=this;e;)e.event("link",[this.href]),e=e.parent},t.formatURL=function(t){return this.URI?y.formatURL(t,this.URI?this.URI.path:null):t},l(0,t,"href",function(){return this._href},function(t){null!=(this._href=t)&&(this._getCSSStyle().underLine=1,this.updateHref())}),l(0,t,"color",null,function(t){this.style.color=t}),l(0,t,"onClick",null,function(t){n._runScript("fn=function(event){"+t+";}"),this.on("click",this,void 0)}),l(0,t,"id",null,function(t){v.document.setElementById(t,this)}),l(0,t,"innerTEXT",function(){return this._text.text},function(t){this.text=t}),l(0,t,"style",function(){return this._style}),l(0,t,"text",function(){return this._text.text},function(t){this._text==e._EMPTYTEXT?this._text={text:t,words:null}:(this._text.text=t,this._text.words&&(this._text.words.length=0)),o.isConchApp&&this.layaoutCallNative(),this._renderType|=2048,this.repaint(),this.updateHref()}),l(0,t,"parent",i.prototype._$get_parent,function(t){var e;t instanceof laya.html.dom.HTMLElement&&(e=t,this.URI||(this.URI=e.URI),this.style.inherit(e.style)),n.superSet(u,this,"parent",t)}),l(0,t,"className",null,function(t){this.style.attrs(v.document.styleSheets["."+t])}),e.fillWords=function(t,e,i,n,h,l,s,r,a){t.graphics.clear();for(var o=0,d=e.length;o<d;o++){var u=e[o];0<r?t.graphics.fillBorderText(u.char,u.x+i,u.y+n,h,l,a,r,"left"):t.graphics.fillText(u.char,u.x+i,u.y+n,h,l,"left",s)}},e._EMPTYTEXT={text:null,words:null},e}(u);h(t,"laya.html.dom.HTMLBrElement",x);function t(){t.__super.call(this),this.style.lineElement=!0,this.style.block=!0}var e=function(t){function e(){this.contextHeight=NaN,this.contextWidth=NaN,e.__super.call(this),this.style.block=!0,this.style.lineElement=!0,this.style.width=200,this.style.height=200}h(e,"laya.html.dom.HTMLDivElement",t);var i=e.prototype;return i.appendHTML=function(t){p.parse(this,t,this.URI),this.layout()},i._addChildsToLayout=function(e){var t=this._getWords();if(null==t&&0==this._childs.length)return!1;t&&t.forEach(function(t){e.push(t)});for(var i=!0,n=0,h=this._childs.length;n<h;n++){var l=this._childs[n];i?i=!1:e.push(null),l._addToLayout(e)}return!0},i._addToLayout=function(t){this.layout()},i.layout=function(){var t,e;this.style&&(this.style._type|=512,(t=w.layout(this))&&(this._$P.mHtmlBounds||this._set$P("mHtmlBounds",new a),(e=this._$P.mHtmlBounds).x=e.y=0,e.width=this.contextWidth=t[0],e.height=this.contextHeight=t[1],this.setBounds(e)))},l(0,i,"height",function(){return this._height||this.contextHeight},t.prototype._$set_height),l(0,i,"innerHTML",null,function(t){this.destroyChildren(),this.appendHTML(t)}),l(0,i,"width",function(){return this._width||this.contextWidth},function(t){var e=!1,e=0===t?t!=this._width:t!=this.width;n.superSet(x,this,"width",t),e&&this.layout()}),e}(x),v=function(){function t(){this.all=new Array,this.styleSheets=s.styleSheets,t.__super.call(this)}h(t,"laya.html.dom.HTMLDocument",x);var e=t.prototype;return e.getElementById=function(t){return this.all[t]},e.setElementById=function(t,e){this.all[t]=e},i(t,["document",function(){return this.document=new t}]),t}();(function(){function t(){this._tex=null,this._url=null,this._renderArgs=[],t.__super.call(this),this.style.block=!0}h(t,"laya.html.dom.HTMLImageElement",x);var e=t.prototype;e._addToLayout=function(t){this._style.absolute||t.push(this)},e.render=function(t,e,i){!this._tex||!this._tex.loaded||!this._tex.loaded||this._width<1||this._height<1||(_.spriteCount++,this._renderArgs[0]=this._tex,this._renderArgs[1]=this.x,this._renderArgs[2]=this.y,this._renderArgs[3]=this.width||this._tex.width,this._renderArgs[4]=this.height||this._tex.height,t.ctx.drawTexture2(e,i,this.style.translateX,this.style.translateY,this.transform,this.style.alpha,this.style.blendMode,this._renderArgs))},e.layaoutCallNative=function(){var t=0;if(this._childs&&0<(t=this._childs.length))for(var e=0;e<t;e++)this._childs[e].layaoutCallNative&&this._childs[e].layaoutCallNative()},l(0,e,"src",null,function(t){var e,i=this;function n(){var t;i._style&&((t=i._style).widthed(i)||i._tex.width,t.heighted(i)||i._tex.height,t.widthed(i)||i._width==i._tex.width||(i.width=i._tex.width,i.parent&&i.parent._layoutLater()),t.heighted(i)||i._height==i._tex.height||(i.height=i._tex.height,i.parent&&i.parent._layoutLater()),o.isConchApp&&(i._renderArgs[0]=i._tex,i._renderArgs[1]=i.x,i._renderArgs[2]=i.y,i._renderArgs[3]=i.width||i._tex.width,i._renderArgs[4]=i.height||i._tex.height,i.graphics.drawTexture(i._tex,0,0,i._renderArgs[3],i._renderArgs[4])),i.repaint(),i.parentRepaint())}t=this.formatURL(t),this._url!=t&&(this._url=t,(e=this._tex=r.getRes(t))||(this._tex=e=new f,e.load(t),r.cacheRes(t,e)),e.loaded?n():e.on("loaded",null,n))})})(),function(t){function e(){this.type=null,e.__super.call(this),this.visible=!1}h(e,"laya.html.dom.HTMLLinkElement",t);var i=e.prototype;i._onload=function(t){"text/css"===this.type&&s.parseCSS(t,this.URI)},l(0,i,"href",t.prototype._$get_href,function(t){var e=this;t=this.formatURL(t),this.URI=new y(t);var i=new r;i.once("complete",null,function(t){e._onload(t)}),i.load(t,"text")}),e._cuttingStyle=new RegExp("((@keyframes[\\s\\t]+|)(.+))[\\t\\n\\r\\s]*{","g")}(x),function(t){function e(){e.__super.call(this),this.visible=!1}h(e,"laya.html.dom.HTMLStyleElement",t);var i=e.prototype;l(0,i,"text",t.prototype._$get_text,function(t){s.parseCSS(t,null)})}(x),function(t){function e(){e.__super.call(this),this._getCSSStyle().valign="middle"}h(e,"laya.html.dom.HTMLIframeElement",t);var i=e.prototype;l(0,i,"href",t.prototype._$get_href,function(i){var n=this;i=this.formatURL(i);var t=new r;t.once("complete",null,function(t){var e=n.URI;n.URI=new y(i),n.innerHTML=t,e&&(n.URI=e)}),t.load(i,"text")})}(e)}((window,document,Laya)),"function"==typeof define&&define.amd&&define("laya.core",["require","exports"],function(t,e){"use strict";for(var i in Object.defineProperty(e,"__esModule",{value:!0}),Laya){var n=Laya[i];n&&n.__isclass&&(e[i]=n)}}); |