UNPKG

shadow-function

Version:

ioing lib - shadow Function, worker Function

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