text: !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).easyCanvas=e()}(this,(function(){"use strict";const t={BLOCK:"block",INLINE_BLOCK:"inline-block",INLINE:"inline",FLEX:"flex",NONE:"none"},e={AUTO:"auto",OUTER:"100%"},i={ROW:"row",COLUMN:"column"};var s={DISPLAY:t,WIDTH:e,POSITION:{ABSOLUTE:"absolute",FIXED:"fixed",RELATIVE:"relative",STATIC:"static"},DEFAULT_STYLES:{display:t.BLOCK,fontSize:14,fontWeight:400,fontFamily:"sans-serif",color:"#000",paddingTop:0,paddingBottom:0,paddingLeft:0,paddingRight:0,marginTop:0,marginBottom:0,marginLeft:0,marginRight:0,height:e.AUTO,borderRadius:0,lineCap:"square",flexDirection:i.ROW,verticalAlign:"middle",textAlign:"left",justifyContent:"flex-start",alignItems:"flex-start",whiteSpace:"normal",zIndex:1,visible:!0,position:"static"},TEXT_ALIGN:{LEFT:"left",RIGHT:"right",CENTER:"center"},FLEX_DIRECTION:i};function n(t){return"number"==typeof t}function r(t){return"auto"===t}function h(t){if("string"==typeof t)return t.match("%")}function o(t){let e=parseInt(t.replace("%",""));return isNaN(e)||e<0?0:e/100}function l(t,e){let i=!1,s=!1;const n=()=>i=!0,r=()=>s=!0;if(null!=t){var h=[];for(h.push(t);0!=h.length;){var o=h.pop();if(e(o,n,r),s)s=!1;else for(var l=o._getChildren(),d=l.length-1;d>=0;d--)i?i=!1:h.push(l[d])}}}function d(t,e){if(!t)return;let i=t,s=!1;const n=()=>{s=!0};for(;i.parent&&(e(i.parent,n),!s);)i=i.parent}function a(){try{return Boolean(wx.getSystemInfoSync)}catch(t){return!1}}function g(t){var e=[];if(null!=t){var i=[];for(i.unshift(t);0!=i.length;){var s=i.shift();e.push(s._generateRender());for(var n=s._getChildren(),r=0;r<n.length;r++)i.push(n[r]._generateRender())}}return e}function c(t){var e=[];if(null!=t){var i=[];for(i.unshift(t);0!=i.length;){var s=i.shift();e.push(s._generateRender());for(var n=s._getChildren(),r=n.length-1;r>=0;r--)i.push(n[r]._generateRender())}}return e.reverse()}const y=["attrs","styles","on"];function p(t){return.5+t<<0}class u{constructor(){this.width=0,this.height=0,this.contentWidth=0,this.y=0,this.doorClosed=!1,this.outerWidth=0,this.container=null,this.elements=[],this.start=null,this.end=null,this.offsetX=0,this.id=Math.random()}bind(t){this.container=t.parent,this.initHeight(t),this.outerWidth=t.parent&&r(t.parent.styles.width)?1/0:t.parent.renderStyles.contentWidth,this.start=t,this.add(t)}initHeight(t){this.height=t.parent&&t.parent.renderStyles.lineHeight||0}initLayout(t){this.right=t._getContainerLayout().contentX,this.x=t._getContainerLayout().contentX,this.y=this.getPreLine(t).y}refreshElementPosition(t){this.start===t&&this.initLayout(t),t.x=this.right+this.offsetX,t.y=this.y+this.getOffsetY(t),this.right+=t.renderStyles.width}getOffsetY(t){return"bottom"===t.renderStyles.verticalAlign?this.height-t.renderStyles.height:"middle"===t.renderStyles.verticalAlign?(this.height-t.renderStyles.height)/2:0}add(t){this.elements.push(t),t.line=this,this.refreshWidthHeight(t),t.next&&"inline-block"===t.next.renderStyles.display||this.closeLine()}refreshWidthHeight(t){t.renderStyles.height>this.height&&(this.height=t.renderStyles.height),this.width+=t.renderStyles.width}canIEnter(t){return!(t.renderStyles.width+this.width>this.outerWidth)||(this.closeLine(),!1)}closeLine(){this.end=this.elements[this.elements.length-1],this.refreshXAlign()}getPreLine(t){return t.pre?t.pre.line?{y:t.pre.line.height+t.pre.line.y,x:t.pre.line.x}:{y:t._getPreLayout().y+t._getPreLayout().height,x:t._getPreLayout().x}:{y:t._getContainerLayout().contentY,x:t._getContainerLayout().contentX}}refreshXAlign(){if(this.outerWidth>5e3)return;if(!this.end.parent)return;let t=this.outerWidth-this.width;"center"===this.end.parent.renderStyles.textAlign?t/=2:"left"===this.end.parent.renderStyles.textAlign&&(t=0),this.offsetX=t}}const f={[s.FLEX_DIRECTION.ROW]:{width:"width",contentWidth:"contentWidth",x:"x",y:"y",contentX:"contentX",height:"height",contentHeight:"contentHeight"},[s.FLEX_DIRECTION.COLUMN]:{width:"height",contentWidth:"contentHeight",x:"y",y:"x",contentX:"contentY",height:"width",contentHeight:"contentWidth"}};class m extends u{constructor(){super(),this.exactValue=0,this.flexTotal=0,this.key=null}closeLine(){super.closeLine(),this.calcFlex()}bind(t){this.container=t.parent,t.parent&&(this.key=f[t.parent.renderStyles.flexDirection]),this.initHeight(t),this.outerWidth=t.parent&&r(t.parent.styles[this.key.width])?1/0:t.parent.renderStyles[this.key.contentWidth],this.start=t,this.add(t)}add(t){n(t.styles[this.key.width])?this.exactValue+=t.renderStyles[this.key.width]:n(t.styles.flex)&&(this.flexTotal+=t.renderStyles.flex),this.elements.push(t),t.line=this,this.refreshWidthHeight(t),t.next||this.closeLine()}initHeight(){this[this.key.height]=0}refreshWidthHeight(t){t.renderStyles[this.key.height]>this[this.key.height]&&(this[this.key.height]=t.renderStyles[this.key.height]),this[this.key.width]+=t.renderStyles[this.key.width]}initLayout(t){this.right=t._getContainerLayout()[this.key.contentX],this[this.key.x]=t._getContainerLayout()[this.key.contentX],this[this.key.y]=this.getPreLine(t)[this.key.y]}refreshElementPosition(t){this.start===t&&this.initLayout(t),t[this.key.x]=this.right+this.offsetX,t[this.key.y]=this[this.key.y]+this.getOffsetY(t),this.right+=t.renderStyles[this.key.width]}calcFlex(){const{[this.key.contentWidth]:t}=this.container.renderStyles;this.elements.forEach(e=>{n(e.styles.flex)&&(e.renderStyles[this.key.width]=e.styles.flex/this.flexTotal*(t-this.exactValue),e._refreshContentWithLayout())})}refreshXAlign(){if(!this.end.parent)return;let t=this.outerWidth-this[this.key.width];"center"===this.end.parent.renderStyles.justifyContent?t/=2:"flex-start"===this.end.parent.renderStyles.justifyContent&&(t=0),this.offsetX=t}getOffsetY(t){return"flex-end"===t.renderStyles.alignSelf?this.container.renderStyles[this.key.contentHeight]-t.renderStyles[this.key.height]:"center"===t.renderStyles.alignSelf?(this.container.renderStyles[this.key.contentHeight]-t.renderStyles[this.key.height])/2:0}}class S{static connectChildren(t){t.hasChildren()&&(t.children=t.children.filter(t=>t instanceof S),t._getChildren().map((e,i)=>{e._setParent(t),e._setSibling(t._getChildren()[i-1],t._getChildren()[i+1]),S.connectChildren(e)}))}constructor(t){this.children=t||[],this.parent=null,this.root=null,this.pre=null,this.next=null}hasChildren(){return!(!Array.isArray(this.children)||!this.children.length)}_getChildren(){return this.hasChildren()?this.children:[]}_setParent(t){this.parent=t,this.root=t.root}_setSibling(t,e){this.pre=t||null,this.next=e||null}appendChild(t){if(!t instanceof S)throw Error("Unknown treeNode type");const e=this._getChildren()[this._getChildren().length-1];e&&e._setSibling(e.pre,t),this.children.push(t),t._setParent(this),t._setSibling(e,null)}prependChild(t){if(!t instanceof S)throw Error("Unknown treeNode type");const e=this._getChildren()[0];e&&e._setSibling(t,e.next),this.children.unshift(t),t._setParent(this),t._setSibling(null,e)}removeChild(t){if(!t instanceof S)throw Error("Unknown treeNode type");const e=this._getChildren().indexOf(t);if(e<0)throw Error("treeNode must be the child of parent");const i=this._getChildren()[e-1],s=this._getChildren()[e+1];i&&i._setSibling(i.pre,s),s&&s._setSibling(i,s.next),this.children.splice(e,1)}remove(){if(!this.parent)throw Error("Can not remove root node");this.parent.removeChild(this)}append(t){if(!t instanceof S)throw Error("Unknown treeNode type");if(!this.parent)throw Error("Can not add treeNode to root level!");let e=[];t._setParent(this.parent),this.parent.children.forEach((i,s)=>{e.push(i),i===this&&(t._setSibling(i,this.parent.children[s+1]),e.push(t))}),this.parent.children=e}prepend(t){if(!t instanceof S)throw Error("Unknown treeNode type");if(!this.parent)throw Error("Can not add treeNode to root level!");let e=[];t._setParent(this.parent);for(let i=this.parent.children.length-1;i>=0;i--)e.unshift(this.parent.children[i]),this.parent.children[i]===this&&(t._setSibling(this.parent.children[i-1],this.parent.children[i]),e.unshift(t));this.parent.children=e}}function x(t){!function(t){t.parent&&t.parent.styles.display===s.DISPLAY.FLEX&&(t.styles.flex?"column"===t.parent.styles.flexDirection&&n(t.styles.flex)?t.styles.height=0:"row"===t.parent.styles.flexDirection&&n(t.styles.flex)&&(t.styles.width=0):n(t.styles.height)||n(t.styles.width)||(t.styles.flex=1))}(t),function(t){t.styles.width||(t.styles.display!==s.DISPLAY.INLINE_BLOCK&&t.styles.display!==s.DISPLAY.INLINE&&t.isInFlow()?t.styles.display===s.DISPLAY.BLOCK||t.styles.display===s.DISPLAY.FLEX?t.styles.width=s.WIDTH.OUTER:t.styles.width=0:t.styles.width=s.WIDTH.AUTO);h(t.styles.width)&&t.parent&&r(t.parent.styles.width)&&(t.styles.width=s.WIDTH.AUTO);h(t.styles.height)&&t.parent&&r(t.parent.styles.height)&&(t.styles.height=s.WIDTH.AUTO)}(t),function(t){let{borderWidth:e,borderLeftWidth:i,borderRightWidth:s,borderBottomWidth:n,borderTopWidth:r,borderRadius:h}=t.styles;e||(t.styles.borderWidth=0,e=0);Array.isArray(e)?(t.styles.borderTopWidth=e[0],t.styles.borderRightWidth=e[1],t.styles.borderBottomWidth=e[2],t.styles.borderLeftWidth=e[3]):(i||(t.styles.borderLeftWidth=e),s||(t.styles.borderRightWidth=e),n||(t.styles.borderBottomWidth=e),r||(t.styles.borderTopWidth=e));h&&(t.styles.overflow="hidden")}(t),function(t){t.styles.fontSize&&!t.styles.lineHeight&&(t.styles.lineHeight=1.4*t.styles.fontSize)}(t),function(t){t.styles.padding&&(n(t.styles.padding)?(t.styles.paddingLeft=t.styles.padding,t.styles.paddingBottom=t.styles.padding,t.styles.paddingRight=t.styles.padding,t.styles.paddingTop=t.styles.padding):Array.isArray(t.styles.padding)&&(2===t.styles.padding.length?(t.styles.paddingLeft=t.styles.paddingRight=t.styles.padding[1],t.styles.paddingBottom=t.styles.paddingTop=t.styles.padding[0]):4===t.styles.padding.length&&(t.styles.paddingLeft=t.styles.padding[3],t.styles.paddingBottom=t.styles.padding[2],t.styles.paddingRight=t.styles.padding[1],t.styles.paddingTop=t.styles.padding[0])));n(t.styles.margin)?(t.styles.marginLeft=t.styles.margin,t.styles.marginBottom=t.styles.margin,t.styles.marginRight=t.styles.margin,t.styles.marginTop=t.styles.margin):Array.isArray(t.styles.margin)&&(2===t.styles.margin.length?(t.styles.marginLeft=t.styles.marginRight=t.styles.margin[1],t.styles.marginBottom=t.styles.marginTop=t.styles.margin[0]):4===t.styles.margin.length&&(t.styles.marginLeft=t.styles.margin[3],t.styles.marginBottom=t.styles.margin[2],t.styles.marginRight=t.styles.margin[1],t.styles.marginTop=t.styles.margin[0]))}(t)}class w extends S{constructor(t,e){super(e),this.options=Object.assign({attrs:{},styles:{},on:{}},t),this.styles=null,this.renderStyles=null,this.x=0,this.y=0,this.render=null,this.container=null,this.visible=!0}init(){this._initStyles(),this.initEvent()}initEvent(){this.options.on&&Object.keys(this.options.on).forEach(t=>{this.getLayer().eventManager.EVENTS.includes(t)&&this.getLayer().eventManager.addEventListener(t,this.options.on[t],this)})}removeEvent(){this.getLayer().eventManager.removeElement(this)}getLayer(){return this.root.layer}getRender(){return this.root.layer.render}_paint(){}mount(t){t.mountNode(this)}_initStyles(){this.styles=Object.assign({},this._getDefaultStyles(),this._getParentStyles(this.options.styles),this.options.styles||{}),this._completeStyles(),this._initRenderStyles()}_initRenderStyles(){const t={...this.styles},e=this._getContainerLayout().contentWidth,i=this._getContainerLayout().contentHeight;r(t.width)?t.paddingWidth=0:h(t.width)?t.paddingWidth=o(t.width)*e-t.marginLeft-t.marginRight:t.paddingWidth=t.width,r(t.height)?t.paddingHeight=0:h(t.height)?t.paddingHeight=o(t.height)*i-t.marginTop-t.marginBottom:t.paddingHeight=t.height,t.paddingWidth||(t.paddingWidth=0),t.paddingHeight||(t.paddingHeight=0),t.contentWidth=t.paddingWidth-t.paddingLeft-t.paddingRight,t.contentHeight=t.paddingHeight-t.paddingTop-t.paddingBottom,t.width=t.paddingWidth+t.marginLeft+t.marginRight+this._getTotalBorderWidth(t),t.height=t.paddingHeight+t.marginTop+t.marginBottom+this._getTotalBorderHeight(t),this.renderStyles=t,this._InFlexBox()?this._bindFlexBox():this.isInFlow()||(this.relativeTo=function(t){if(t.isInFlow())return t.parent;if("fixed"===t.renderStyles.position)return t.root;let e=null;return d(t,t=>{"static"===t.renderStyles.position||e||(e=t)}),e||(e=t.root),e}(this))}_getParentStyles(t){let{textAlign:e,lineHeight:i,fontSize:s,color:n,fontFamily:r,alignItems:h,visible:o=!0}=this.parent&&this.parent.renderStyles||{},l={};return e&&(l.textAlign=e),s&&(l.fontSize=s),n&&(l.color=n),r&&(l.fontFamily=r),h&&!t.alignSelf&&(l.alignSelf=h),l.visible=o,l}_completeStyles(){x(this)}_getDefaultStyles(){return s.DEFAULT_STYLES}_getChildrenInFlow(){return this._getChildren().filter(t=>t.isInFlow())}isInFlow(){const{position:t,display:e}=this.styles;return t!==s.POSITION.ABSOLUTE&&t!==s.POSITION.FIXED}isVisible(){return this.renderStyles.visible&&this.visible}_generateRender(){return this}getCtx(){return this.root.layer.ctx}_reflow(){}_initWidthHeight(){const{width:t,height:e,display:i,flex:n,marginLeft:h,marginRight:o,marginTop:l,marginBottom:d}=this.styles;if(r(t)||r(e)){const i=this._measureLayout();r(t)&&(this.renderStyles.contentWidth=p(i.width)),r(e)&&(this.renderStyles.contentHeight=p(i.height))}this._refreshLayoutWithContent(),this._InFlexBox()?this.line.refreshWidthHeight(this):i===s.DISPLAY.INLINE_BLOCK&&this._bindLine()}_initPosition(){let{contentX:t}=this._getContainerLayout();const{paddingLeft:e,paddingTop:i,borderLeftWidth:r,borderTopWidth:l,marginLeft:d,marginTop:a}=this.renderStyles;if(this.isInFlow())this._InFlexBox()||this.renderStyles.display===s.DISPLAY.INLINE_BLOCK?this.line.refreshElementPosition(this):(this.x=t,this.y=this._getPreLayout().y+this._getPreLayout().height);else{let{contentX:t,contentY:e,contentWidth:i,contentHeight:s}=this._getContainerLayout(this.relativeTo),{top:r,bottom:l,right:d,left:a,width:g,height:c}=this.renderStyles;h(r)&&(r=o(r)*s),h(l)&&(l=o(l)*s),h(a)&&(a=o(a)*i),h(d)&&(d=o(d)*i),n(r)?this.y=e+r:n(l)&&(this.y=e+s-l-c),n(a)?this.x=t+a:n(d)&&(this.x=t+i-d-g)}this.x=p(this.x),this.y=p(this.y),this.contentX=this.x+e+r+d,this.contentY=this.y+i+l+a}_InFlexBox(){return!!this.isInFlow()&&(!!this.parent&&(!(!this.parent||this.parent.renderStyles.display!==s.DISPLAY.FLEX)||void 0))}_refreshLayoutWithContent(){this.renderStyles.height=p(this.renderStyles.contentHeight+this.renderStyles.paddingTop+this.renderStyles.paddingBottom+this.renderStyles.marginTop+this.renderStyles.marginBottom+this._getTotalBorderHeight()),this.renderStyles.width=p(this.renderStyles.contentWidth+this.renderStyles.paddingLeft+this.renderStyles.paddingRight+this.renderStyles.marginLeft+this.renderStyles.marginRight+this._getTotalBorderWidth()),this.renderStyles.paddingWidth=p(this.renderStyles.contentWidth+this.renderStyles.paddingLeft+this.renderStyles.paddingRight),this.renderStyles.paddingHeight=p(this.renderStyles.contentHeight+this.renderStyles.paddingTop+this.renderStyles.paddingBottom)}_refreshContentWithLayout(){this.renderStyles.contentHeight=this.renderStyles.height-this.renderStyles.paddingTop-this.renderStyles.paddingBottom-this.renderStyles.marginTop-this.renderStyles.marginBottom-this._getTotalBorderHeight(),this.renderStyles.contentWidth=this.renderStyles.width-this.renderStyles.paddingLeft-this.renderStyles.paddingRight-this.renderStyles.marginLeft-this.renderStyles.marginRight-this._getTotalBorderWidth(),this.renderStyles.paddingWidth=p(this.renderStyles.contentWidth+this.renderStyles.paddingLeft+this.renderStyles.paddingRight),this.renderStyles.paddingHeight=p(this.renderStyles.contentHeight+this.renderStyles.paddingTop+this.renderStyles.paddingBottom)}_getTotalBorderWidth(t=this.renderStyles){return t.borderLeftWidth+t.borderRightWidth}_getTotalBorderHeight(t=this.renderStyles){return t.borderTopWidth+t.borderBottomWidth}_bindLine(){this.pre&&this.pre.line&&this.pre.line.canIEnter(this)?this.pre.line.add(this):(new u).bind(this)}_bindFlexBox(){this.pre&&this.pre.line?this.pre.line.add(this):(new m).bind(this)}_getContainerLayout(t=this.parent){return t||(this.container,t={renderStyles:{width:this.container.width,height:this.container.height,paddingTop:0,paddingBottom:0,paddingLeft:0,paddingRight:0,marginLeft:0,marginRight:0,marginTop:0,marginBottom:0,contentWidth:this.container.width,contentHeight:this.container.height},x:0,y:0,contentX:0,contentY:0}),{width:t.renderStyles.width,height:t.renderStyles.height,x:t.x,y:t.y,paddingTop:t.renderStyles.paddingTop,paddingBottom:t.renderStyles.paddingBottom,paddingLeft:t.renderStyles.paddingLeft,paddingRight:t.renderStyles.paddingRight,marginLeft:t.renderStyles.marginLeft,marginRight:t.renderStyles.marginRight,marginTop:t.renderStyles.marginTop,marginBottom:t.renderStyles.marginBottom,contentX:t.contentX,contentY:t.contentY,contentWidth:t.renderStyles.contentWidth,contentHeight:t.renderStyles.contentHeight}}_getPreLayout(){let t=this.pre;for(;t&&!t.isInFlow();)t=t.pre;return t?{width:t.renderStyles.width,height:t.renderStyles.height,x:t.x,y:t.y}:{width:0,height:0,x:this._getContainerLayout().contentX,y:this._getContainerLayout().contentY}}_measureLayout(){let t=0,e=0;return this._getChildrenInFlow().forEach(i=>{i.line?i.line.start===i&&(i.line.width>t&&(t=i.line.width),e+=i.line.height):i.renderStyles.width>t?(t=i.renderStyles.width,e+=i.renderStyles.height):e+=i.renderStyles.height}),{width:t,height:e}}getElementBy(t,e){let i=[];return l(this,s=>{s.options.attrs[t]===e&&i.push(s)}),i}appendChild(t){return super.appendChild(t),this.getLayer().onElementAdd(t),t}prependChild(t){return super.prependChild(t),this.getLayer().onElementAdd(t),t}removeChild(t){super.removeChild(t),this.getLayer().onElementRemove(t)}append(t){super.append(t),this.getLayer().onElementAdd(t)}prepend(t){super.prepend(t),this.getLayer().onElementAdd(t)}setStyles(t){let e=!1;Object.keys(t).forEach(i=>{["width","height","position","display","padding","paddingTop","paddingLeft","paddingBottom","paddingRight","margin","marginLeft","marginTop","marginBottom","marginRight","borderWidth","flexDirection","justifyContent","alignItems","textAlign","left","top","right","bottom"].includes(i)?e=!0:this.renderStyles[i]=t[i]}),e?(Object.keys(t).forEach(e=>{this.options.styles[e]=t[e]}),this.getLayer().reflowElement(this,this)):this.getRender().requestRepaint()}}class _ extends w{constructor(t,e){super(t,e),this.type="view"}_getDefaultStyles(){return{...s.DEFAULT_STYLES,display:s.DISPLAY.BLOCK}}_paint(){this.getRender()._drawBackground(this),this.getRender()._drawBox(this)}}class L extends w{constructor(t,e){super(t,e),this._layout=null,this._lines=[],this.children+="",this.type="text",this.debugColor="blue"}_paint(){this.getRender()._drawBackground(this),this.getRender()._drawText(this),this.getRender()._drawBox(this)}_getDefaultStyles(){return{...s.DEFAULT_STYLES,display:s.DISPLAY.INLINE_BLOCK,width:s.WIDTH.AUTO,textAlign:"left"}}_measureLayout(){return this._layout=this.getRender().measureText(this,this.children),this._layout.height=this.renderStyles.lineHeight,this._calcLine(),this._layout}_getFont(){const{fontSize:t,fontWeight:e,fontFamily:i}=this.renderStyles;return`${e} ${t}px ${i}`}_calcLine(){if(!this.parent||!this.children)return;const{width:t,height:e}=this._layout;let{contentWidth:i}=this.parent.renderStyles;const{width:h}=this.parent.styles;if(r(this.styles.width)||(i=this.renderStyles.width),n(i)&&i>=t||h===s.WIDTH.AUTO)this._lines=[{text:this.children,layout:this._layout}];else{this._lines=[];let t=1,e="",s=null,n=null;for(let r=0;r<this.children.length;r++){if(s=this.getRender().measureText(this,e+this.children[r]),s.width>i){if(t>=this.renderStyles.maxLine){e=e.substring(0,e.length-2)+"...";break}this._lines.push({text:e,layout:n||s}),e="",t+=1}e+=this.children[r],n=s}this._layout.width=i,this._lines.push({text:e,layout:this.getRender().measureText(this,e)}),this._layout.height=this._lines.length*this.renderStyles.lineHeight}}getInnerText(){return this.children}setInnerText(t){void 0!==t&&t!==this.children&&(this.children=t,this.getLayer().reflowElement(this))}}class C extends _{constructor(t,e){super(t,e),this.type="image",this._imageInfo={width:0,height:0,sx:0,sy:0,swidth:0,sheight:0,dx:0,dy:0,dwidth:0,dheight:0},this.debugColor="blue",this._image=null,this._layout=null}init(){super.init(),this.options&&this.options.attrs&&this.options.attrs.timeout?setTimeout(()=>{this._loadImage()},this.options.attrs.timeout||0):this._loadImage()}_paint(){this.getRender()._drawBackground(this),this.getRender()._drawImage(this),this.getRender()._drawBox(this)}_loadImage(){const{mode:t}=this.options.attrs;return new Promise((t,e)=>{this.getRender().getImageInstance(this.options.attrs.src).then(({info:e,image:i})=>{this._imageInfo=e,this._image=i,t(),this._layoutImage(),this.isVisible()&&this.getLayer().reflowElement(this),this.options.on&&this.options.on.load&&this.options.on.load(this)}).catch(t=>{this.options.on&&this.options.on.error&&this.options.on.error(t)})})}_layoutImage(){const{contentWidth:t,contentHeight:e}=this.renderStyles,{mode:i}=this.options.attrs,{width:s,height:n}=this.styles,{width:h,height:o}=this._imageInfo;let l=t,d=e;!r(s)&&r(n)?(l=t,d=T(l,h,o)):!r(n)&&r(s)?(d=e,l=b(d,h,o)):r(s)&&r(n)?(l=h,d=o):"aspectFill"===i?l/d>h/o?(this._imageInfo.swidth=h,this._imageInfo.sheight=T(h,l,d),this._imageInfo.sx=0,this._imageInfo.sy=(o-this._imageInfo.sheight)/2):(this._imageInfo.sheight=o,this._imageInfo.swidth=b(o,t,e),this._imageInfo.sy=0,this._imageInfo.sx=(h-this._imageInfo.swidth)/2):"aspectFit"===i?l/d>h/o?(this._imageInfo.dwidth=b(e,h,o),this._imageInfo.dheight=e,this._imageInfo.dy=this.contentY,this._imageInfo.dx=(t-this._imageInfo.dwidth)/2+this.contentX):(this._imageInfo.dheight=T(t,h,o),this._imageInfo.dwidth=t,this._imageInfo.dx=this.contentX,this._imageInfo.dy=(e-this._imageInfo.dheight)/2+this.contentY):(l=t,d=e),this._layout={width:l,height:d}}_measureLayout(){return this._layout?this._layout:{width:this.renderStyles.width,height:this.renderStyles.height}}}function b(t,e,i){return t/i*e}function T(t,e,i){return t/e*i}const I=["click","touchstart","touchmove","touchend","mousewheel"];class E{constructor({simulateClick:t=!0}){this.EVENTS=I,this.clear(),this.touchStartEvent=null,this.simulateClick=t}clear(){I.forEach(t=>{this[t+"Tree"]=new S,this[t+"List"]=[]})}click(t,e){let i=new v({x:t,y:e,type:"click"});this._emit(i)}touchstart(t,e){let i=new v({x:t,y:e,type:"touchstart"});this.touchStartEvent=i,this._emit(i)}touchmove(t,e){let i=new v({x:t,y:e,type:"touchmove"});this._emit(i)}touchend(t,e){let i=new v({x:t,y:e,type:"touchend"});this._emit(i),this.checkClick(i)}mousewheel(t,e,i,s){let n=new v({x:t,y:e,deltaX:i,deltaY:s,type:"mousewheel"});this._emit(n)}_emit(t){let e=this[t.type+"Tree"];if(!e)return;let i=[],s=e._getChildren();for(;s.length;)W(s,(e,n,r)=>{e.element.isVisible()&&this.isPointInElement(t.relativeX,t.relativeY,e.element)?(e.runCapture(t),i.unshift(e),n(),s=e._getChildren()):r&&(s=[])});for(let e=0;e<i.length&&(t.currentTarget||(t.currentTarget=i[e].element),i[e].runCallback(t),!t.cancelBubble);e++);}isPointInElement(t,e,i){let s=t>=i.x,n=e>=i.y,r=t<=i.x+i.renderStyles.width,h=e<=i.y+i.renderStyles.height;return!!(s&&n&&r&&h)}removeElement(t){I.forEach(e=>{this[e+"List"]=this[e+"List"].filter(e=>(e.element===t&&e.remove(),e.element!==t))})}addEventListener(t,e,i,s){const n=this[t+"Tree"],r=this[t+"List"];n||console.error("Unknown event name ["+t+"]"),this.addCallback(e,i,n,r,s)}addCallback(t,e,i,s,n){let r=null,h=null,o=e;for(let t=s.length-1;t>=0;t--){if(e===s[t].element){r=s[t-1],h=s[t];break}if(!e.isInFlow()&&(o=e.relativeTo.parent,!o))break;if(d(o,(e,i)=>{e===s[t].element&&(r=s[t],i())}),r)break}h||(h=new B(e,t)),n?h.addCapture(t):h.addCallback(t),r?r.prependChild(h):i.prependChild(h),s.push(h)}checkClick(t){if(this.touchStartEvent&&this.simulateClick){let{x:e,y:i}=this.touchStartEvent,{x:s,y:n}=t,r=n*n+s*s-(i*i+e*e);r<5&&r>-5&&this.click(s,n)}}}class v{constructor({x:t,y:e,type:i,deltaX:s,deltaY:n}){this.x=t,this.y=e,this.relativeX=t,this.relativeY=e,this.type=i,this.cancelBubble=!1,this.currentTarget=null,"mousewheel"===i&&(this.deltaX=s,this.deltaY=n)}stopPropagation(){this.cancelBubble=!0}}class B extends S{constructor(t){super(),this.element=t,this.callbackList=[],this.captureList=[]}addCallback(t){this.callbackList.push(t)}addCapture(t){this.captureList.push(t)}runCallback(t){this.callbackList.forEach(e=>e.call(this.element,t))}runCapture(t){this.captureList.forEach(e=>e.call(this.element,t))}}function W(t,e){let i=!1;const s=()=>i=!0;for(let n=0;n<t.length&&(e(t[n],s,n===t.length-1),!i);n++);}const R=Math.PI/2;class k{constructor(t){this.layer=t,this.imageBus={},this.isAnimate=!1,this.lastPaintTime=0,this.lastFrameComplete=!1,this.throttle=function(t){let e;return function(i){e||(e=setTimeout((function(){i(),e=null}),t))}}(16)}isDebug(){return this.getLayer().options&&this.getLayer().options.debug}getCtx(){return this.layer.ctx}getLayer(){return this.layer}_restore(t){this.getCtx().save(),t(),this.getCtx().restore()}_path(t){this.getCtx().beginPath(),t(),this.getCtx().closePath()}paint(t){this.getCtx().save(),t._paint(this.lastPaintTime),this.afterPaint(t)}afterPaint(t){t.hasChildren()&&"text"!==t.type||this.getCtx().restore(),this._helpParentRestoreCtx(t)}_helpParentRestoreCtx(t){if(t.isVisible()&&(!(e=t).parent||e.next||e.hasChildren())||!t.isVisible()&&t.next)return;var e;this.getCtx().restore();let i=t.parent;for(;i&&!i.next;)this.getCtx().restore(),i=i.parent}topBorder({x:t,y:e,borderRadius:i,w:s,h:n}){this.getCtx().moveTo(t,e+i),i&&this.getCtx().arc(t+i,e+i,i,2*R,3*R),this.getCtx().lineTo(t+s-i,e)}rightBorder({x:t,y:e,borderRadius:i,w:s,h:n}){i&&this.getCtx().arc(t+s-i,e+i,i,3*R,4*R),this.getCtx().lineTo(t+s,e+n-i)}bottomBorder({x:t,y:e,borderRadius:i,w:s,h:n}){i&&this.getCtx().arc(t+s-i,e+n-i,i,0,R),this.getCtx().lineTo(t+i,e+n)}leftBorder({x:t,y:e,borderRadius:i,w:s,h:n}){i&&this.getCtx().arc(t+i,e+n-i,i,R,2*R),this.getCtx().lineTo(t,e+i)}_drawBox(t){if(!t.renderStyles.borderColor&&!t.renderStyles.shadowBlur)return;const{contentWidth:e,contentHeight:i,paddingLeft:s,paddingTop:n,borderStyle:r,paddingRight:h,paddingBottom:o,shadowBlur:l,shadowColor:d,backgroundColor:a,shadowOffsetX:g,shadowOffsetY:c,borderLeftWidth:y,borderRightWidth:p,borderTopWidth:u,borderBottomWidth:f,borderWidth:m}=t.renderStyles;let S=X(t),x=t.contentX-t.renderStyles.paddingLeft-y/2,w=t.contentY-t.renderStyles.paddingTop-u/2,_=e+s+h+(y+p)/2,L=i+n+o+(u+f)/2;this.getCtx().lineCap=t.renderStyles.lineCap,this.getCtx().strokeStyle=t.renderStyles.borderColor,this.getCtx().lineJoin="round",r&&"solid"!==r&&(Array.isArray(r)?this.getCtx().setLineDash(r):this.getCtx().setLineDash([5,5]));const C=t=>{this.getCtx().lineWidth=t,this.getCtx().stroke()};this._restore(()=>{this._path(()=>{t.renderStyles.borderTopWidth&&(this.topBorder({x:x,y:w,borderRadius:S?S+t.renderStyles.borderTopWidth/2:0,w:_,h:L}),!m&&C(t.renderStyles.borderTopWidth)),t.renderStyles.borderRightWidth&&(this.getCtx().moveTo(x+_-S-(S?t.renderStyles.borderTopWidth/2:0),w),this.rightBorder({x:x,y:w,borderRadius:S?S+t.renderStyles.borderRightWidth/2:0,w:_,h:L}),!m&&C(t.renderStyles.borderRightWidth)),t.renderStyles.borderBottomWidth&&(this.getCtx().moveTo(x+_,w+L-S-(S?t.renderStyles.borderRightWidth/2:0)),this.bottomBorder({x:x,y:w,borderRadius:S?S+t.renderStyles.borderBottomWidth/2:0,w:_,h:L}),!m&&C(t.renderStyles.borderBottomWidth)),t.renderStyles.borderLeftWidth&&(this.getCtx().moveTo(x+S+(S?t.renderStyles.borderBottomWidth/2:0),w+L),this.leftBorder({x:x,y:w,borderRadius:S?S+t.renderStyles.borderLeftWidth/2:0,w:_,h:L}),C(t.renderStyles.borderLeftWidth))})})}_drawBackground(t){const{backgroundColor:e,contentWidth:i,contentHeight:s,shadowColor:r,shadowBlur:h,paddingLeft:o,paddingRight:l,paddingTop:d,paddingBottom:a,opacity:g,shadowOffsetX:c,shadowOffsetY:y,borderLeftWidth:p,borderRightWidth:u,borderTopWidth:f,borderBottomWidth:m}=t.renderStyles,S=this.getCtx();let x=X(t),w=t.contentX-t.renderStyles.paddingLeft-p,_=t.contentY-t.renderStyles.paddingTop-f,L=i+o+l+(p+u),C=s+d+a+(f+m);n(g)&&(S.globalAlpha=g),r&&h&&this._restore(()=>{this._path(()=>{this.topBorder({x:w,y:_,borderRadius:x,w:L,h:C}),this.rightBorder({x:w,y:_,borderRadius:x,w:L,h:C}),this.bottomBorder({x:w,y:_,borderRadius:x,w:L,h:C}),this.leftBorder({x:w,y:_,borderRadius:x,w:L,h:C})}),n(c)&&(this.getCtx().shadowOffsetX=c),n(y)&&(this.getCtx().shadowOffsetY=y),this.getCtx().shadowBlur=h,this.getCtx().shadowColor=r,this.getCtx().fillStyle=r,this.getCtx().fill()}),this._clip(t),e&&(this.getCtx().fillStyle=this._parseBackground(e,t),this.getCtx().fillRect(t.contentX-o,t.contentY-d,i+o+l,s+d+a)),this.isDebug()&&(this.getCtx().strokeStyle=t.debugColor||"green",this.getCtx().strokeRect(t.contentX,t.contentY,t.renderStyles.contentWidth,t.renderStyles.contentHeight))}_clip(t){if("hidden"!==t.renderStyles.overflow)return;const{contentWidth:e,contentHeight:i,paddingLeft:s,paddingTop:n,paddingRight:r,paddingBottom:h,shadowBlur:o,shadowColor:l,backgroundColor:d,borderLeftWidth:a,borderRightWidth:g,borderTopWidth:c,borderBottomWidth:y}=t.renderStyles;let p=X(t),u=t.contentX-t.renderStyles.paddingLeft-a,f=t.contentY-t.renderStyles.paddingTop-c,m=e+s+r+a+g,S=i+n+h+c+y;this._path(()=>{this.topBorder({x:u,y:f,borderRadius:p,w:m,h:S}),this.rightBorder({x:u,y:f,borderRadius:p,w:m,h:S}),this.bottomBorder({x:u,y:f,borderRadius:p,w:m,h:S}),this.leftBorder({x:u,y:f,borderRadius:p,w:m,h:S})}),this.getCtx().clip()}_parseBackground(t,e){if(Array.isArray(t)){const i=this.getCtx().createLinearGradient(e.contentX,e.contentY,e.contentX+e.renderStyles.contentWidth,e.contentY+e.renderStyles.contentHeight);for(let e=0;e<t.length;e++)0===e?i.addColorStop(0,t[0]):i.addColorStop(e/(t.length-1),t[e]);return i}return t}_drawText(t){const{color:e,contentWidth:i,lineHeight:n,textAlign:r,textIndent:h,textDecoration:o}=t.renderStyles;let l=t.contentX;this.getCtx().fillStyle=e,this.getCtx().textAlign=r,this.getCtx().font=t._getFont(),this.getCtx().textBaseline="middle",r===s.TEXT_ALIGN.RIGHT?l=t.contentX+i:r===s.TEXT_ALIGN.CENTER&&(l=t.contentX+i/2);let d=l,g=0;t._lines.forEach((i,s)=>{if(d=0===s&&h?l+h:l,g=t.contentY+n/2+n*s,this.isDebug()&&this.getCtx().fillRect(d,g,2,2),this.getCtx().fillText(i.text,d,g),a()&&400!==t.renderStyles.fontWeight){const e=.001*t.renderStyles.fontSize;this.getCtx().fillText(i.text,d-e,g)}if(o){const s=o[0];g+=1,this._restore(()=>{this._path(()=>{let e=g;"underline"===s?e=g+t._layout.fontHeight/2:"line-through"===s&&(e=g),this.getCtx().moveTo(d,e),this.getCtx().lineTo(d+i.layout.width,e)}),this.getCtx().strokeStyle=e,this.getCtx().stroke()})}})}measureText(t,e){let i=0,s=0;return this._restore(()=>{this.getCtx().font=t._getFont();const{width:n,actualBoundingBoxAscent:r}=this.getCtx().measureText(e);i=n,s=r||.7*t.renderStyles.fontSize}),{width:i,fontHeight:s+1}}_drawImage(t){if(!t._image)return;const{contentWidth:e,contentHeight:i}=t.renderStyles,{mode:s}=t.options.attrs,{sx:n,sy:r,swidth:h,sheight:o,dx:l,dy:d,dwidth:a,dheight:g,width:c,height:y}=t._imageInfo;"aspectFill"===s?this.getCtx().drawImage(t._image,n,r,h,o,t.contentX,t.contentY,e,i):"aspectFit"===s?this.getCtx().drawImage(t._image,0,0,c,y,l,d,a,g):this.getCtx().drawImage(t._image,t.contentX,t.contentY,e,i)}_drawScroll(t){this.getCtx().translate(t.currentScrollX,t.currentScrollY)}getImageInstance(t){let e=null;return this.imageBus[t]?e=this.imageBus[t]:(a()?this.getCanvas()?e=this.getCanvas().createImage():(console.warn("小程序请使用设置canvas参数以创建图片"),e=function(t){const e={onload:()=>{}};return new Promise((e,i)=>{wx.downloadFile({url:t,success(t){wx.getImageInfo({src:t.tempFilePath,success(i){e({target:{width:i.width,height:i.height},image:t.tempFilePath})}})},fail(t){i(t)}})}).then(t=>{e.onload(t)}).catch(t=>{}),e}(t)):e=new Image,t&&(this.imageBus[t]=new Promise((t,i)=>{e.onload=i=>{t({image:a()&&!this.getCanvas()?i.image:e,info:{width:a()?e.width:i.target.width,height:a()?e.height:i.target.height}})},e.onerror=t=>{i(t)}})),e.src=t),this.imageBus[t]}render(t){this.lastFrameComplete=!1,this.lastPaintTime=Date.now(),t.parent?this.getCtx().clearRect(t.x,t.y,t.renderStyles.width,t.renderStyles.height):this.getCtx().clearRect(0,0,this.getLayer().options.width,this.getLayer().options.height),l(t,(t,e,i)=>{t.isVisible()?this.paint(t):(i(),this._helpParentRestoreCtx(t))}),a()&&this.getCtx().draw&&this.getCtx().draw(),this.lastFrameComplete=!0}renderFPS(){}readyToRender(t){this.element=t;const e=this.getLayer().options;this.lastPaintTime=Date.now(),e&&e.animate?this.animate():this.render(this.element)}requestRepaint(t){this.isAnimate||this.render(this.element)}getCanvas(){const t=this.getLayer().options;return t&&t.canvas||null}_animate(t){const e=Date.now();this.render(this.element),this.isAnimate&&window.requestAnimationFrame(()=>this._animate(e))}animate(){this.isAnimate=!0,window.requestAnimationFrame(()=>this._animate())}stopAnimate(){this.isAnimate=!1}onEffectFinished(){const t=Object.keys(this.imageBus).map(t=>this.imageBus[t]);return Promise.all(t)}}function X(t){const{paddingWidth:e,paddingHeight:i}=t.renderStyles;let{borderRadius:s}=t.renderStyles;return 2*s>e&&(s=e/2),2*s>i&&(s=i/2),s<0&&(s=0),p(s)}class A{constructor(t,e){this.ctx=t,this.node=null,this.isAnimate=!1,this.nodeList=[],this.p2cList=[],this.c2pList=[],this.renderList=[],this.options=e,this.eventManager=new E(e),this.render=new k(this)}update(t,e){this.ctx=t,this.options=e,this.options.renderStyles=e,this.node.container=this.options}mountNode(t){this.node=t,this.node.root=this.node,this.node.layer=this,this.node.container=this.options,this.eventManager.clear(),this.initRender()}initRender(){const t=Date.now();S.connectChildren(this.node),this.initP2CList(),this.initC2PList(),this.flow(),this.render.onEffectFinished().then(t=>this.lifecycle("onEffectSuccess",t)).catch(t=>this.lifecycle("onEffectFail",t)),this.repaint(),console.log(`渲染${this.p2cList.length}个元素 耗时 ${Date.now()-t} ms`)}initP2CList(){this.p2cList=g(this.node)}initC2PList(){this.c2pList=c(this.node)}flow(t=this.node){for(let t=0;t<this.p2cList.length;t++)this.p2cList[t].init();this.reflow()}initPaintList(){this.renderList=this.nodeList}reflow(t=this.node){for(let t=0;t<this.c2pList.length;t++)this.c2pList[t]._initWidthHeight();for(let t=0;t<this.p2cList.length;t++)this.p2cList[t]._initPosition()}reflowElement(t){let e=t;for(;e&&e.line;)e=e.parent;const i=g(e);for(let t=0;t<i.length;t++)i[t]._initStyles();const s=c(e);for(let t=0;t<s.length;t++)s[t]._initWidthHeight();if(t.isInFlow())this.onElementChange(e);else{for(let t=0;t<i.length;t++)i[t]._initPosition();this.repaint()}}onElementRemove(t){this.eventManager.removeElement(t),this.initC2PList(),this.initP2CList(),this.reflowElement(t)}onElementAdd(t){S.connectChildren(t),this.initC2PList(),this.initP2CList(),g(t).forEach(t=>t.init()),this.reflowElement(t)}onElementChange(t){d(t,(t,e)=>{t._initWidthHeight(),"scroll-view"===t.type&&e()});for(let t=0;t<this.p2cList.length;t++)this.p2cList[t]._initPosition();this.repaint()}callBeforePaint(){for(let t=0;t<this.p2cList.length;t++)this.p2cList[t].beforePaint&&this.p2cList[t].beforePaint()}repaint(t=this.node){a()&&(t=this.node),t.isInFlow()||(t=this.node),this.callBeforePaint(),this.render.readyToRender(this.node)}animate(){console.warn("use [animate] option instead!")}getElementBy(){return this.node.getElementBy(...arguments)}lifecycle(t,e){this.options.lifecycle&&this.options.lifecycle[t]&&this.options.lifecycle[t](e)}}class P extends _{constructor(t,e){const{styles:i,...s}=t;return super(s,e),this.options.styles={direction:i.direction||"y"},t.styles.overflow="hidden",this.type="scroll-view",this._scrollView=new _(t,[this]),this._scrollView.type="scroll-view-container",this.visibleIndex=null,this.renderOnDemand=t.attrs&&t.attrs.renderOnDemand||!1,this._scrollView}_getDefaultStyles(){return{...s.DEFAULT_STYLES,direction:"y"}}beforePaint(){this.initChildrenVisible()}_initWidthHeight(){super._initWidthHeight(),this.initScroll()}_paint(){this.getRender()._drawBackground(this),this.getRender()._drawScroll(this),this.getRender()._drawBox(this)}init(){super.init(),this.addEventListener();const{height:t,width:e}=this._scrollView.styles,{direction:i}=this.styles;i.match("y")&&(r(t)?console.error("scroll-view 必须设置明确的高度"):(this.styles.height="auto",this.renderStyles.height="auto")),i.match("x")&&(r(e)?console.error("scroll-view 必须设置明确的宽度"):(this.styles.width="auto",this.renderStyles.width="auto"))}addEventListener(){this.currentScrollX=0,this.currentScrollY=0;let t=this.styles.direction,e=0,i=0,s=0,n=0,r=!1,h=0,o=0,l=0,d=0,a=null,g=1,c=1;this.getLayer().eventManager.EVENTS.forEach(e=>{this.getLayer().eventManager.addEventListener(e,e=>{t.match("y")&&(e.relativeY-=this.currentScrollY),t.match("x")&&(e.relativeX-=this.currentScrollX)},this._scrollView,!0)}),this.getLayer().eventManager.addEventListener("mousewheel",t=>{this.scrollBy(t.deltaX,t.deltaY)?t.stopPropagation():this.scrollTo({x:t.deltaX<=0?this.maxScrollX:0,y:t.deltaY<=0?this.maxScrollY:0})},this._scrollView),this.getLayer().eventManager.addEventListener("touchstart",t=>{t.stopPropagation(),e=t.x,i=t.y,s=e,n=i,r=!0,clearInterval(a)},this._scrollView),this.getLayer().eventManager.addEventListener("touchmove",t=>{r&&(t.stopPropagation(),h=t.x-e,o=t.y-i,this.scrollBy(h,o)&&(s=e,n=i,e=t.x,i=t.y))},this._scrollView),this.getLayer().eventManager.addEventListener("touchend",t=>{r&&(r=!1,l=t.x-s,d=t.y-n,g=.02*-l,c=.02*-d,clearInterval(a),a=setInterval(()=>{this.scrollBy(l,d)||(this.scrollTo(this.currentScrollX+l,this.currentScrollY+d),clearInterval(a)),l+=g,d+=c,l*l<=.05&&d*d<=.05&&(l=0,d=0,clearInterval(a))},16))},this._scrollView)}initScroll(){const{contentWidth:t,contentHeight:e}=this._scrollView.renderStyles,{width:i,height:s,direction:n}=this.renderStyles;this.maxScrollX=i-t,this.maxScrollY=s-e}calcScrollBoundX(t){return!(-this.currentScrollX-t>this.maxScrollX)&&!(this.currentScrollX+t>0)}calcScrollBoundY(t){return!(-this.currentScrollY-t>this.maxScrollY)&&!(this.currentScrollY+t>0)}scrollByX(t){return!!this.renderStyles.direction.match("x")&&(!!this.calcScrollBoundX(t)&&(this.currentScrollX+=t,!0))}scrollByY(t){return!!this.renderStyles.direction.match("y")&&(!!this.calcScrollBoundY(t)&&(this.currentScrollY+=p(t),this.calcChildrenVisible(),!0))}scrollBy(t,e){return!!(this.scrollByX(t)|this.scrollByY(e))&&(this.getRender().requestRepaint(this._scrollView),!0)}scrollTo({x:t,y:e}){n(t)&&this.maxScrollX>0&&((t=t)>this.maxScrollX&&(t=this.maxScrollX),this.currentScrollX=-p(t)),n(e)&&this.maxScrollY>0&&((e=e)>this.maxScrollY&&(e=this.maxScrollY),this.currentScrollY=-p(e)),this.initChildrenVisible(),this.getRender().requestRepaint(this._scrollView)}initChildrenVisible(){if(!this.renderOnDemand)return;const t=this._getChildrenInFlow();for(let e=0;e<t.length;e++){if(this.isElementInViewport(t[e])){this.visibleIndex=[e,-1];break}t[e].visible=!1}for(let e=t.length-1;e>=0;e--){if(this.isElementInViewport(t[e])){this.visibleIndex[1]=e;break}t[e].visible=!1}for(let e=this.visibleIndex[0];e<=this.visibleIndex[1];e++)t[e].visible=!0}calcChildrenVisible(){if(!this.renderOnDemand)return;const t=this._getChildrenInFlow(),e=H(this.visibleIndex[0],5),i=H(this.visibleIndex[1],5);let s=[];for(let i=e[0];i<=e[e.length-1];i++)t[i]&&(this.isElementInViewport(t[i])?(t[i].visible=!0,s.length||s.push(i)):t[i].visible=!1);for(let e=i[i.length-1];e>=i[0];e--)t[e]&&(this.isElementInViewport(t[e])?(t[e].visible=!0,1===s.length&&s.push(e)):t[e].visible=!1);this.visibleIndex=s,this.visibleIndex.length<2&&this.initChildrenVisible()}isElementInViewport(t){return!this.styles.direction.match("y")||t.y+t.renderStyles.height+this.currentScrollY>this._scrollView.contentY&&t.y+this.currentScrollY<this._scrollView.contentY+this._scrollView.renderStyles.contentHeight}}function H(t,e){let i=t+e,s=[];for(let n=t-e;n<=i;n++)s.push(n);return s}const Y={};function F(t,e){if(Y[t])throw Error(`Already exist tag name [${t}] !`);Y[t]=e}F("view",(t,e)=>new _(t,e)),F("text",(t,e)=>new L(t,e)),F("image",(t,e)=>new C(t,e)),F("scroll-view",(t,e)=>new P(t,e)),F("scrollview",(t,e)=>new P(t,e));return{createLayer:function(t,e){return new A(t,e)},createElement:function(t){return t((function t(e,i={},s=[]){let n=null,r=s;if(!Y[e])throw Error(`Unknown tag name [${e}] !`);if("string"==typeof s&&"text"!==e)r=[new L({},s)];else if(!Array.isArray(s)&&"text"!==e)throw Error(`Element [${e}]:Children must be type of Array!`);return n=Y[e](i,r,t),n}))},component:F,View:_,Text:L,Image:C,Layer:A,ScrollView:P,mergeOptions:function(t,e){let i={};return y.forEach(s=>{t[s]||(t[s]={}),e[s]||(e[s]={}),i[s]=Object.assign({},t[s],i[s])}),i}}}));
  