diff --git a/build/amd/hilo-amd.js b/build/amd/hilo-amd.js index efc17054..faacf331 100644 --- a/build/amd/hilo-amd.js +++ b/build/amd/hilo-amd.js @@ -1,5 +1,5 @@ /** - * Hilo 1.5.0 for amd + * Hilo 1.6.0 for amd * Copyright 2016 alibaba.com * Licensed under the MIT License */ @@ -192,7 +192,7 @@ return browser; }); /** - * Hilo 1.5.0 for amd + * Hilo 1.6.0 for amd * Copyright 2016 alibaba.com * Licensed under the MIT License */ @@ -229,7 +229,7 @@ return util; }); /** - * Hilo 1.5.0 for amd + * Hilo 1.6.0 for amd * Copyright 2016 alibaba.com * Licensed under the MIT License */ @@ -257,7 +257,7 @@ var Hilo = { * Hilo version * @type String */ - version: '1.5.0', + version: '1.6.0', /** * @language=en * Gets a globally unique id. Such as Stage1, Bitmap2 etc. @@ -565,7 +565,7 @@ return Hilo; }); /** - * Hilo 1.5.0 for amd + * Hilo 1.6.0 for amd * Copyright 2016 alibaba.com * Licensed under the MIT License */ @@ -748,7 +748,7 @@ return Class; }); /** - * Hilo 1.5.0 for amd + * Hilo 1.6.0 for amd * Copyright 2016 alibaba.com * Licensed under the MIT License */ @@ -972,7 +972,7 @@ return Matrix; }); /** - * Hilo 1.5.0 for amd + * Hilo 1.6.0 for amd * Copyright 2016 alibaba.com * Licensed under the MIT License */ @@ -1125,7 +1125,7 @@ return EventMixin; }); /** - * Hilo 1.5.0 for amd + * Hilo 1.6.0 for amd * Copyright 2016 alibaba.com * Licensed under the MIT License */ @@ -1206,7 +1206,7 @@ return Drawable; }); /** - * Hilo 1.5.0 for amd + * Hilo 1.6.0 for amd * Copyright 2016 alibaba.com * Licensed under the MIT License */ @@ -1300,7 +1300,7 @@ return Renderer; }); /** - * Hilo 1.5.0 for amd + * Hilo 1.6.0 for amd * Copyright 2016 alibaba.com * Licensed under the MIT License */ @@ -1511,7 +1511,7 @@ return CanvasRenderer; }); /** - * Hilo 1.5.0 for amd + * Hilo 1.6.0 for amd * Copyright 2016 alibaba.com * Licensed under the MIT License */ @@ -1693,7 +1693,7 @@ return DOMRenderer; }); /** - * Hilo 1.5.0 for amd + * Hilo 1.6.0 for amd * Copyright 2016 alibaba.com * Licensed under the MIT License */ @@ -2277,7 +2277,7 @@ return WebGLRenderer; }); /** - * Hilo 1.5.0 for amd + * Hilo 1.6.0 for amd * Copyright 2016 alibaba.com * Licensed under the MIT License */ @@ -2774,7 +2774,7 @@ return View; }); /** - * Hilo 1.5.0 for amd + * Hilo 1.6.0 for amd * Copyright 2016 alibaba.com * Licensed under the MIT License */ @@ -2840,7 +2840,7 @@ return CacheMixin; }); /** - * Hilo 1.5.0 for amd + * Hilo 1.6.0 for amd * Copyright 2016 alibaba.com * Licensed under the MIT License */ @@ -3214,7 +3214,7 @@ return Container; }); /** - * Hilo 1.5.0 for amd + * Hilo 1.6.0 for amd * Copyright 2016 alibaba.com * Licensed under the MIT License */ @@ -3481,7 +3481,7 @@ return Stage; }); /** - * Hilo 1.5.0 for amd + * Hilo 1.6.0 for amd * Copyright 2016 alibaba.com * Licensed under the MIT License */ @@ -3536,7 +3536,7 @@ define('hilo/view/Bitmap', ['hilo/core/Hilo', 'hilo/core/Class', 'hilo/view/View * set the image。 * @param {Image|String} Image Object or URL. * @param {Array} rect the range of bitmap in the image, option. - * @param {Boolean} Whether cross-domain is needed, default is false. + * @param {Boolean} crossOrigin Whether cross-domain is needed, default is false. * @returns {Bitmap} self。 */ setImage: function(image, rect, crossOrigin){ @@ -3561,7 +3561,7 @@ return Bitmap; }); /** - * Hilo 1.5.0 for amd + * Hilo 1.6.0 for amd * Copyright 2016 alibaba.com * Licensed under the MIT License */ @@ -3832,7 +3832,7 @@ return Sprite; }); /** - * Hilo 1.5.0 for amd + * Hilo 1.6.0 for amd * Copyright 2016 alibaba.com * Licensed under the MIT License */ @@ -3947,7 +3947,7 @@ return DOMElement; }); /** - * Hilo 1.5.0 for amd + * Hilo 1.6.0 for amd * Copyright 2016 alibaba.com * Licensed under the MIT License */ @@ -4509,7 +4509,7 @@ return Graphics; }); /** - * Hilo 1.5.0 for amd + * Hilo 1.6.0 for amd * Copyright 2016 alibaba.com * Licensed under the MIT License */ @@ -4762,7 +4762,7 @@ return Text; }); /** - * Hilo 1.5.0 for amd + * Hilo 1.6.0 for amd * Copyright 2016 alibaba.com * Licensed under the MIT License */ @@ -4946,7 +4946,7 @@ return BitmapText; }); /** - * Hilo 1.5.0 for amd + * Hilo 1.6.0 for amd * Copyright 2016 alibaba.com * Licensed under the MIT License */ @@ -5125,7 +5125,7 @@ return Button; }); /** - * Hilo 1.5.0 for amd + * Hilo 1.6.0 for amd * Copyright 2016 alibaba.com * Licensed under the MIT License */ @@ -5362,7 +5362,7 @@ return TextureAtlas; }); /** - * Hilo 1.5.0 for amd + * Hilo 1.6.0 for amd * Copyright 2016 alibaba.com * Licensed under the MIT License */ @@ -5591,7 +5591,7 @@ return Ticker; }); /** - * Hilo 1.5.0 for amd + * Hilo 1.6.0 for amd * Copyright 2016 alibaba.com * Licensed under the MIT License */ @@ -5639,7 +5639,7 @@ if (!fnProto.bind) { }); /** - * Hilo 1.5.0 for amd + * Hilo 1.6.0 for amd * Copyright 2016 alibaba.com * Licensed under the MIT License */ @@ -5778,7 +5778,7 @@ return drag; }); /** - * Hilo 1.5.0 for amd + * Hilo 1.6.0 for amd * Copyright 2016 alibaba.com * Licensed under the MIT License */ @@ -6234,7 +6234,7 @@ return Tween; }); /** - * Hilo 1.5.0 for amd + * Hilo 1.6.0 for amd * Copyright 2016 alibaba.com * Licensed under the MIT License */ @@ -6506,7 +6506,7 @@ return Ease; }); /** - * Hilo 1.5.0 for amd + * Hilo 1.6.0 for amd * Copyright 2016 alibaba.com * Licensed under the MIT License */ @@ -6554,7 +6554,7 @@ return ImageLoader; }); /** - * Hilo 1.5.0 for amd + * Hilo 1.6.0 for amd * Copyright 2016 alibaba.com * Licensed under the MIT License */ @@ -6621,7 +6621,7 @@ return ScriptLoader; }); /** - * Hilo 1.5.0 for amd + * Hilo 1.6.0 for amd * Copyright 2016 alibaba.com * Licensed under the MIT License */ @@ -6713,6 +6713,23 @@ var LoadQueue = Class.create(/** @lends LoadQueue.prototype */{ var item = this.get(id); return item && item.content; }, + /** + * @language=en + * remove resource object content by id or src + * @param {String} specified id or src + */ + removeContent: function(id){ + if(id){ + var source = this._source; + for(var i = 0; i < source.length; i++){ + var item = source[i]; + if(item.id === id || item.src === id){ + source.splice(i, 1); + return; + } + } + } + }, /** * @language=en @@ -6871,7 +6888,7 @@ return LoadQueue; }); /** - * Hilo 1.5.0 for amd + * Hilo 1.6.0 for amd * Copyright 2016 alibaba.com * Licensed under the MIT License */ @@ -7074,7 +7091,7 @@ return HTMLAudio; }); /** - * Hilo 1.5.0 for amd + * Hilo 1.6.0 for amd * Copyright 2016 alibaba.com * Licensed under the MIT License */ @@ -7398,7 +7415,7 @@ return WebAudio; }); /** - * Hilo 1.5.0 for amd + * Hilo 1.6.0 for amd * Copyright 2016 alibaba.com * Licensed under the MIT License */ @@ -7501,7 +7518,7 @@ return WebSound; }); /** - * Hilo 1.5.0 for amd + * Hilo 1.6.0 for amd * Copyright 2016 alibaba.com * Licensed under the MIT License */ @@ -7594,7 +7611,7 @@ return Camera; }); /** - * Hilo 1.5.0 for amd + * Hilo 1.6.0 for amd * Copyright 2016 alibaba.com * Licensed under the MIT License */ @@ -7781,7 +7798,7 @@ return Camera3d; }); /** - * Hilo 1.5.0 for amd + * Hilo 1.6.0 for amd * Copyright 2016 alibaba.com * Licensed under the MIT License */ diff --git a/build/amd/hilo-amd.min.js b/build/amd/hilo-amd.min.js index 7c1cb39f..f28a9623 100644 --- a/build/amd/hilo-amd.min.js +++ b/build/amd/hilo-amd.min.js @@ -1,8 +1,8 @@ /** - * Hilo 1.5.0 for amd + * Hilo 1.6.0 for amd * Copyright 2016 alibaba.com * Licensed under the MIT License */ -define("hilo/util/browser",function(){var t=function(){var t=navigator.userAgent,e=document,i=window,r=e.documentElement,n={iphone:/iphone/i.test(t),ipad:/ipad/i.test(t),ipod:/ipod/i.test(t),ios:/iphone|ipad|ipod/i.test(t),android:/android/i.test(t),webkit:/webkit/i.test(t),chrome:/chrome/i.test(t),safari:/safari/i.test(t),firefox:/firefox/i.test(t),ie:/msie/i.test(t),opera:/opera/i.test(t),supportTouch:"ontouchstart"in i,supportCanvas:null!=e.createElement("canvas").getContext,supportStorage:!1,supportOrientation:"orientation"in i||"orientation"in i.screen,supportDeviceMotion:"ondevicemotion"in i};try{var a="hilo";localStorage.setItem(a,a),localStorage.removeItem(a),n.supportStorage=!0}catch(o){}var s=n.jsVendor=n.webkit?"webkit":n.firefox?"webkit":n.opera?"o":n.ie?"ms":"",h=n.cssVendor="-"+s+"-",l=e.createElement("div"),c=l.style,u=void 0!=c[s+"Transform"],d=void 0!=c[s+"Perspective"];d&&(l.id="test3d",c=e.createElement("style"),c.textContent="@media ("+h+"transform-3d){#test3d{height:3px}}",e.head.appendChild(c),r.appendChild(l),d=3==l.offsetHeight,e.head.removeChild(c),r.removeChild(l)),n.supportTransform=u,n.supportTransform3D=d;var f=n.supportTouch,p=f?"touchstart":"mousedown",v=f?"touchmove":"mousemove",m=f?"touchend":"mouseup";return n.POINTER_START=p,n.POINTER_MOVE=v,n.POINTER_END=m,n}();return t}),define("hilo/util/util",function(){var t={copy:function(t,e,i){for(var r in e)i&&!t.hasOwnProperty(r)&&void 0===t[r]||(t[r]=e[r]);return t}};return t}),define("hilo/core/Hilo",["hilo/util/browser","hilo/util/util"],function(t,e){var i=window,r=document,n=r.documentElement,a=0,o={},s={version:"1.5.0",getUid:function(t){var e=++a;if(t){var i=t.charCodeAt(t.length-1);return i>=48&&i<=57&&(t+="_"),t+e}return e},viewToString:function(t){for(var e,i=t;i;)e=e?i.id+"."+e:i.id,i=i.parent;return e},copy:function(t,i,r){return e.copy(t,i,r),o.copy||(o.copy=!0,console.warn("Hilo.copy has been Deprecated! Use Hilo.util.copy instead.")),t},browser:t,event:{POINTER_START:t.POINTER_START,POINTER_MOVE:t.POINTER_MOVE,POINTER_END:t.POINTER_END},align:{TOP_LEFT:"TL",TOP:"T",TOP_RIGHT:"TR",LEFT:"L",CENTER:"C",RIGHT:"R",BOTTOM_LEFT:"BL",BOTTOM:"B",BOTTOM_RIGHT:"BR"},getElementRect:function(t){var e;try{e=t.getBoundingClientRect()}catch(r){e={top:t.offsetTop,left:t.offsetLeft,right:t.offsetLeft+t.offsetWidth,bottom:t.offsetTop+t.offsetHeight}}var a=(i.pageXOffset||n.scrollLeft)-(n.clientLeft||0)||0,o=(i.pageYOffset||n.scrollTop)-(n.clientTop||0)||0,s=i.getComputedStyle?getComputedStyle(t):t.currentStyle,h=parseInt,l=h(s.paddingLeft)+h(s.borderLeftWidth)||0,c=h(s.paddingTop)+h(s.borderTopWidth)||0,u=h(s.paddingRight)+h(s.borderRightWidth)||0,d=h(s.paddingBottom)+h(s.borderBottomWidth)||0,f=e.top||0,p=e.left||0,v=e.right||0,m=e.bottom||0;return{left:p+a+l,top:f+o+c,width:v-u-p-l,height:m-d-f-c}},createElement:function(t,e){var i,n,a,o=r.createElement(t);for(i in e)if(n=e[i],"style"===i)for(a in n)o.style[a]=n[a];else o[i]=n;return o},getElement:function(t){return r.getElementById(t)},setElementStyleByView:function(t){var e=t.drawable,i=e.domElement.style,r=t._stateCache||(t._stateCache={}),n=s.browser.jsVendor,a="px",o=!1;if(this.cacheStateIfChanged(t,["visible"],r)&&(i.display=t.visible?"":"none"),this.cacheStateIfChanged(t,["alpha"],r)&&(i.opacity=t.alpha),t.visible&&!(t.alpha<=0)){if(this.cacheStateIfChanged(t,["width"],r)&&(i.width=t.width+a),this.cacheStateIfChanged(t,["height"],r)&&(i.height=t.height+a),this.cacheStateIfChanged(t,["depth"],r)&&(i.zIndex=t.depth+1),t.transform){var h=t.transform;(o=this.cacheStateIfChanged(t,["pivotX","pivotY"],r))&&(i[n+"TransformOrigin"]="0 0"),i[n+"Transform"]="matrix3d("+h.a+", "+h.b+", 0, 0, "+h.c+", "+h.d+", 0, 0, 0, 0, 1, 0, "+h.tx+", "+h.ty+", 0, 1)"}else(o=this.cacheStateIfChanged(t,["pivotX","pivotY"],r))&&(i[n+"TransformOrigin"]=t.pivotX+a+" "+t.pivotY+a),(this.cacheStateIfChanged(t,["x","y","rotation","scaleX","scaleY"],r)||o)&&(i[n+"Transform"]=this.getTransformCSS(t));this.cacheStateIfChanged(t,["background"],r)&&(i.backgroundColor=t.background),i.pointerEvents||(i.pointerEvents="none");var l=e.image;if(l){var c=l.src;c!==r.image&&(r.image=c,i.backgroundImage="url("+c+")");var u=e.rect;if(u){var d=u[0],f=u[1];d!==r.sx&&(r.sx=d,i.backgroundPositionX=-d+a),f!==r.sy&&(r.sy=f,i.backgroundPositionY=-f+a)}}var p=t.mask;if(p){var v=p.drawable.domElement.style.backgroundImage;v!==r.maskImage&&(r.maskImage=v,i[n+"MaskImage"]=v,i[n+"MaskRepeat"]="no-repeat");var m=p.x,g=p.y;m===r.maskX&&g===r.maskY||(r.maskX=m,r.maskY=g,i[n+"MaskPosition"]=m+a+" "+g+a)}}},cacheStateIfChanged:function(t,e,i){var r,n,a,o,s=!1;for(r=0,n=e.length;r=6?(e=s[0],i=s[1],r=s[2],n=s[3],a=s[4],o=s[5]):(e=t.a,i=t.b,r=t.c,n=t.d,a=t.tx,o=t.ty),this.a=h*e+l*r,this.b=h*i+l*n,this.c=c*e+u*r,this.d=c*i+u*n,this.tx=d*e+f*r+a,this.ty=d*i+f*n+o,this},rotate:function(t){var e=Math.sin(t),i=Math.cos(t),r=this.a,n=this.b,a=this.c,o=this.d,s=this.tx,h=this.ty;return this.a=r*i-n*e,this.b=r*e+n*i,this.c=a*i-o*e,this.d=a*e+o*i,this.tx=s*i-h*e,this.ty=s*e+h*i,this},scale:function(t,e){return this.a*=t,this.d*=e,this.c*=t,this.b*=e,this.tx*=t,this.ty*=e,this},translate:function(t,e){return this.tx+=t,this.ty+=e,this},identity:function(){return this.a=this.d=1,this.b=this.c=this.tx=this.ty=0,this},invert:function(){var t=this.a,e=this.b,i=this.c,r=this.d,n=this.tx,a=t*r-e*i;return this.a=r/a,this.b=-e/a,this.c=-i/a,this.d=t/a,this.tx=(i*this.ty-r*n)/a,this.ty=-(t*this.ty-e*n)/a,this},transformPoint:function(t,e,i){var r=t.x*this.a+t.y*this.c+this.tx,n=t.x*this.b+t.y*this.d+this.ty;return e&&(r=r+.5>>0,n=n+.5>>0),i?{x:r,y:n}:(t.x=r,t.y=n,t)}});return e}),define("hilo/event/EventMixin",["hilo/core/Class"],function(t){var e={_listeners:null,on:function(t,e,i){for(var r=this._listeners=this._listeners||{},n=r[t]=r[t]||[],a=0,o=n.length;a-1&&o.splice(c,1)}}return 0==o.length&&delete a[n],!0}return!1}},i=t.create({constructor:function(t,e,i){this.type=t,this.target=e,this.detail=i,this.timeStamp=+new Date},type:null,target:null,detail:null,timeStamp:0,stopImmediatePropagation:function(){this._stopped=!0}}),r=window.Event;if(r){var n=r.prototype,a=n.stopImmediatePropagation;n.stopImmediatePropagation=function(){a&&a.call(this),this._stopped=!0}}return e}),define("hilo/view/Drawable",["hilo/core/Class","hilo/util/util"],function(t,e){var i=t.create({constructor:function(t){this.init(t)},image:null,rect:null,init:function(t){var r=this,n=r.image;i.isDrawable(t)?r.image=t:e.copy(r,t,!0);var a=r.image;if("string"==typeof a){if(!n||a!==n.getAttribute("src")){r.image=null;var o=new Image;return t.crossOrigin&&(o.crossOrigin="Anonymous"),o.onload=function(){o.onload=null,r.init(o)},void(o.src=a)}a=r.image=n}a&&!r.rect&&(r.rect=[0,0,a.width,a.height])},Statics:{isDrawable:function(t){if(!t||!t.tagName)return!1;var e=t.tagName.toLowerCase();return"img"===e||"canvas"===e||"video"===e}}});return i}),define("hilo/renderer/Renderer",["hilo/core/Class","hilo/util/util"],function(t,e){var i=t.create({constructor:function(t){t=t||{},e.copy(this,t,!0)},renderType:null,canvas:null,stage:null,blendMode:"source-over",startDraw:function(t){},draw:function(t){},endDraw:function(t){},transform:function(){},hide:function(){},remove:function(t){},clear:function(t,e,i,r){},resize:function(t,e){}});return i}),define("hilo/renderer/CanvasRenderer",["hilo/core/Class","hilo/core/Hilo","hilo/renderer/Renderer"],function(t,e,i){var r=t.create({Extends:i,constructor:function(t){r.superclass.constructor.call(this,t),this.context=this.canvas.getContext("2d")},renderType:"canvas",context:null,startDraw:function(t){return!!(t.visible&&t.alpha>0)&&(t===this.stage&&this.context.clearRect(0,0,t.width,t.height),t.blendMode!==this.blendMode&&(this.context.globalCompositeOperation=this.blendMode=t.blendMode),this.context.save(),!0)},draw:function(t){var e=this.context,i=t.width,r=t.height,n=t.background;n&&(e.fillStyle=n,e.fillRect(0,0,i,r));var a=t.drawable,o=a&&a.image;if(o){var s=a.rect,h=s[2],l=s[3],c=s[4],u=s[5];if(!h||!l)return;i||r||(i=t.width=h,r=t.height=l),(c||u)&&e.translate(c-.5*h,u-.5*l),e.drawImage(o,s[0],s[1],h,l,0,0,i,r)}},endDraw:function(t){this.context.restore()},transform:function(t){var i=t.drawable;if(i&&i.domElement)return void e.setElementStyleByView(t);var r=this.context,n=t.scaleX,a=t.scaleY;if(t===this.stage){var o=this.canvas.style,s=t._scaleX,h=t._scaleY,l=!1;(!s&&1!=n||s&&s!=n)&&(t._scaleX=n,o.width=n*t.width+"px",l=!0),(!h&&1!=a||h&&h!=a)&&(t._scaleY=a,o.height=a*t.height+"px",l=!0),l&&t.updateViewport()}else{var c=t.x,u=t.y,d=t.pivotX,f=t.pivotY,p=t.rotation%360,v=t.transform,m=t.mask;m&&(m._render(this),r.clip());var g=t.align;if(g){var _=t.getAlignPosition();c=_.x,u=_.y}v?r.transform(v.a,v.b,v.c,v.d,v.tx,v.ty):(0==c&&0==u||r.translate(c,u),0!=p&&r.rotate(p*Math.PI/180),1==n&&1==a||r.scale(n,a),0==d&&0==f||r.translate(-d,-f))}t.alpha>0&&(r.globalAlpha*=t.alpha)},remove:function(t){var e=t.drawable,i=e&&e.domElement;if(i){var r=i.parentNode;r&&r.removeChild(i)}},clear:function(t,e,i,r){this.context.clearRect(t,e,i,r)},resize:function(t,e){var i=this.canvas,r=this.stage,n=i.style;i.width=t,i.height=e,n.width=r.width*r.scaleX+"px",n.height=r.height*r.scaleY+"px"}});return r}),define("hilo/renderer/DOMRenderer",["hilo/core/Class","hilo/core/Hilo","hilo/renderer/Renderer","hilo/view/Drawable"],function(t,e,i,r){var n=function(){function a(t,i){var r=t.tagName||"div",n=i.image,a=t.width||n&&n.width,o=t.height||n&&n.height,s=e.createElement(r),h=s.style;if(t.id&&(s.id=t.id),h.position="absolute",h.left=(t.left||0)+"px",h.top=(t.top||0)+"px",h.width=a+"px",h.height=o+"px","canvas"==r){if(s.width=a,s.height=o,n){var l=s.getContext("2d"),c=i.rect||[0,0,a,o];l.drawImage(n,c[0],c[1],c[2],c[3],t.x||0,t.y||0,t.width||c[2],t.height||c[3])}}else if(h.opacity=void 0!=t.alpha?t.alpha:1,(t===this.stage||t.clipChildren)&&(h.overflow="hidden"),n&&n.src){h.backgroundImage="url("+n.src+")";var u=t.rectX||0,d=t.rectY||0;h.backgroundPosition=-u+"px "+-d+"px"}return s}return t.create({Extends:i,constructor:function(t){n.superclass.constructor.call(this,t)},renderType:"dom",startDraw:function(t){var e=t.drawable=t.drawable||new r;return e.domElement=e.domElement||a(t,e),!0},draw:function(t){var e=t.parent,i=t.drawable.domElement,r=i.parentNode;if(e){var n=e.drawable.domElement;if(n!=r&&n.appendChild(i),!t.width&&!t.height){var a=t.drawable.rect;a&&(a[2]||a[3])&&(t.width=a[2],t.height=a[3])}}else t!==this.stage||r||(i.style.overflow="hidden",this.canvas.appendChild(i))},transform:function(t){if(e.setElementStyleByView(t),t===this.stage){var i=this.canvas.style,r=t._scaleX,n=t._scaleY,a=t.scaleX,o=t.scaleY;(!r&&1!=a||r&&r!=a)&&(t._scaleX=a,i.width=a*t.width+"px"),(!n&&1!=o||n&&n!=o)&&(t._scaleY=o,i.height=o*t.height+"px")}},remove:function(t){var e=t.drawable,i=e&&e.domElement;if(i){var r=i.parentNode;r&&r.removeChild(i)}},hide:function(t){var e=t.drawable&&t.drawable.domElement;e&&(e.style.display="none")},resize:function(t,e){var i=this.canvas.style;i.width=t+"px",i.height=e+"px","absolute"!=i.position&&(i.position="relative")}})}();return n}),define("hilo/renderer/WebGLRenderer",["hilo/core/Class","hilo/core/Hilo","hilo/renderer/Renderer","hilo/geom/Matrix"],function(t,e,i,r){var n=Math.PI/180,a=t.create({Extends:i,Statics:{MAX_BATCH_NUM:2e3,ATTRIBUTE_NUM:5,isSupport:function(){if(void 0==this._isSupported){var t=document.createElement("canvas");t.getContext&&(t.getContext("webgl")||t.getContext("experimental-webgl"))?this._isSupported=!0:this._isSupported=!1}return this._isSupported},contextOptions:null},renderType:"webgl",gl:null,_isContextLost:!1,_cacheTexture:{},constructor:function(t){a.superclass.constructor.call(this,t);var e=this,i=a.contextOptions||{};this.gl=this.canvas.getContext("webgl",i)||this.canvas.getContext("experimental-webgl",i),this.maxBatchNum=a.MAX_BATCH_NUM,this.positionStride=4*a.ATTRIBUTE_NUM;var r=this.maxBatchNum*a.ATTRIBUTE_NUM*4,n=6*this.maxBatchNum;this.arrayBuffer=new ArrayBuffer(4*r),this.float32Array=new Float32Array(this.arrayBuffer),this.uint32Array=new Uint32Array(this.arrayBuffer),this.indexs=new Uint16Array(n);for(var o=0,s=0;o0)&&(t===this.stage&&this.clear(),!0)},draw:function(t){var e=t.width,i=t.height,r=(t.background,t.drawable),n=r&&r.image;if(n){var a=r.rect,o=a[2],s=a[3];e||i||(e=t.width=o,i=t.height=s),this.batchIndex>=this.maxBatchNum&&this._renderBatches();var h=this._createVertexs(n,a[0],a[1],o,s,0,0,e,i),l=this.batchIndex*this.positionStride,c=this.float32Array,u=this.uint32Array,d=(t.tint>>16)+(65280&t.tint)+((255&t.tint)<<16)+(255*t.__webglRenderAlpha<<24);c[l+0]=h[0],c[l+1]=h[1],c[l+2]=h[2],c[l+3]=h[3],u[l+4]=d,c[l+5]=h[4],c[l+6]=h[5],c[l+7]=h[6],c[l+8]=h[7],u[l+9]=d,c[l+10]=h[8],c[l+11]=h[9],c[l+12]=h[10],c[l+13]=h[11],u[l+14]=d,c[l+15]=h[12],c[l+16]=h[13],c[l+17]=h[14],c[l+18]=h[15],u[l+19]=d;for(var f=t.__webglWorldMatrix,p=0;p<4;p++){var v=c[l+5*p],m=c[l+5*p+1];c[l+5*p]=f.a*v+f.c*m+f.tx,c[l+5*p+1]=f.b*v+f.d*m+f.ty}t.__textureImage=n,this.sprites[this.batchIndex++]=t}},endDraw:function(t){t===this.stage&&this._renderBatches()},transform:function(t){var i=t.drawable;if(i&&i.domElement)return void e.setElementStyleByView(t);var n=t.scaleX,a=t.scaleY;if(t===this.stage){var o=this.canvas.style,s=t._scaleX,h=t._scaleY,l=!1;(!s&&1!=n||s&&s!=n)&&(t._scaleX=n,o.width=n*t.width+"px",l=!0),(!h&&1!=a||h&&h!=a)&&(t._scaleY=a,o.height=a*t.height+"px",l=!0),l&&t.updateViewport(),t.__webglWorldMatrix=t.__webglWorldMatrix||new r(1,0,0,1,0,0)}else t.parent&&(t.__webglWorldMatrix=t.__webglWorldMatrix||new r(1,0,0,1,0,0),this._setConcatenatedMatrix(t,t.parent));t.alpha>0&&(t.parent&&t.parent.__webglRenderAlpha?t.__webglRenderAlpha=t.alpha*t.parent.__webglRenderAlpha:t.__webglRenderAlpha=t.alpha)},remove:function(t){var e=t.drawable,i=e&&e.domElement;if(i){var r=i.parentNode;r&&r.removeChild(i)}},clear:function(t,e,i,r){this.gl.clear(this.gl.COLOR_BUFFER_BIT)},resize:function(t,e){if(this.width!==t||this.height!==e){var i=this.canvas,r=this.stage,n=i.style;this.width=i.width=t,this.height=i.height=e,n.width=r.width*r.scaleX+"px",n.height=r.height*r.scaleY+"px",this.gl.viewport(0,0,t,e),this.canvasHalfWidth=.5*t,this.canvasHalfHeight=.5*e,this._uploadProjectionTransform(!0)}},_renderBatches:function(){var t=this.gl;t.bufferSubData(t.ARRAY_BUFFER,0,this.uint32Array.subarray(0,this.batchIndex*this.positionStride));for(var e=0,i=0,r=null,n=0;n0&&(i.bindTexture(i.TEXTURE_2D,this._getTexture(this.sprites[t])),i.drawElements(i.TRIANGLES,6*r,i.UNSIGNED_SHORT,6*t*2))},_uploadProjectionTransform:function(t){this._projectionTransformElements&&!t||(this._projectionTransformElements=new Float32Array([1/this.canvasHalfWidth,0,0,0,-1/this.canvasHalfHeight,0,-1,1,1])),this.gl.uniformMatrix3fv(this.u_projectionTransform,!1,this._projectionTransformElements)},_initShaders:function(){var t=" attribute vec2 a_position;\n attribute vec2 a_TexCoord;\n attribute vec4 a_tint;\n uniform mat3 u_projectionTransform;\n varying vec2 v_TexCoord;\n varying vec4 v_tint;\n void main(){\n gl_Position = vec4((u_projectionTransform * vec3(a_position, 1.0)).xy, 1.0, 1.0);\n v_TexCoord = a_TexCoord;\n v_tint = vec4(a_tint.rgb * a_tint.a, a_tint.a);\n }\n ",e="\n precision mediump float;\n uniform sampler2D u_Sampler;\n varying vec2 v_TexCoord;\n varying vec4 v_tint;\n void main(){\n gl_FragColor = texture2D(u_Sampler, v_TexCoord) * v_tint;\n }\n ";this.defaultShader=new o(this,{v:t,f:e},{attributes:["a_position","a_TexCoord","a_tint"],uniforms:["u_projectionTransform","u_Sampler"]})},_createVertexs:function(t,e,i,r,n,a,o,s,h){var l=this.__tempVertexs||[],c=t.width,u=t.height;r/=c,n/=u,e/=c,i/=u,s=s,h=h,a=a,o=o,r+e>1&&(r=1-e),n+i>1&&(n=1-i);var d=0;return l[d++]=a,l[d++]=o,l[d++]=e,l[d++]=i,l[d++]=a+s,l[d++]=o,l[d++]=e+r,l[d++]=i,l[d++]=a,l[d++]=o+h,l[d++]=e,l[d++]=i+n,l[d++]=a+s,l[d++]=o+h,l[d++]=e+r,l[d++]=i+n,l},_setConcatenatedMatrix:function(t,e){var i=t.__webglWorldMatrix,r=1,a=0,o=t.rotation%360,s=t.pivotX,h=t.pivotY,l=t.scaleX,c=t.scaleY,u=t.transform;if(u)i.copy(u);else{if(o){var d=o*n;r=Math.cos(d),a=Math.sin(d)}var f=t.getAlignPosition();i.a=r*l,i.b=a*l,i.c=-a*c,i.d=r*c,i.tx=f.x-i.a*s-i.c*h,i.ty=f.y-i.b*s-i.d*h}i.concat(e.__webglWorldMatrix)},_getTexture:function(t){var e=t.__textureImage,i=this._cacheTexture[e.src];return i||(i=this.activeShader.uploadTexture(e)),i}}),o=function(t,e,i){this.renderer=t,this.gl=t.gl,this.program=this._createProgram(this.gl,e.v,e.f),i=i||{},this.attributes=i.attributes||[],this.uniforms=i.uniforms||[]};return o.prototype={active:function(){var t=this,e=t.renderer,i=t.gl,r=t.program;r&&i&&(e.activeShader=t,i.useProgram(r),t.attributes.forEach(function(t){e[t]=i.getAttribLocation(r,t),i.enableVertexAttribArray(e[t])}),t.uniforms.forEach(function(t){e[t]=i.getUniformLocation(r,t)}),t.width===e.width&&t.height===e.height||(t.width=e.width,t.height=e.height,e._uploadProjectionTransform()))},uploadTexture:function(t){var e=this.gl,i=this.renderer,r=e.createTexture(),n=i.u_Sampler;return e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,r),e.pixelStorei(e.UNPACK_PREMULTIPLY_ALPHA_WEBGL,1),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,t),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.uniform1i(n,0),e.bindTexture(e.TEXTURE_2D,null),this.renderer._cacheTexture[t.src]=r,r},_createProgram:function(t,e,i){var r=this._createShader(t,t.VERTEX_SHADER,e),n=this._createShader(t,t.FRAGMENT_SHADER,i);if(!r||!n)return null;var a=t.createProgram();if(a){t.attachShader(a,r),t.attachShader(a,n),t.linkProgram(a),t.deleteShader(n),t.deleteShader(r);var o=t.getProgramParameter(a,t.LINK_STATUS);if(!o){var s=t.getProgramInfoLog(a);return console.log("Failed to link program: "+s),t.deleteProgram(a),null}}return a},_createShader:function(t,e,i){var r=t.createShader(e);if(r){t.shaderSource(r,i),t.compileShader(r);var n=t.getShaderParameter(r,t.COMPILE_STATUS);if(!n){var a=t.getShaderInfoLog(r);return console.log("Failed to compile shader: "+a),t.deleteShader(r),null}}return r}},a}),define("hilo/view/View",["hilo/core/Hilo","hilo/core/Class","hilo/event/EventMixin","hilo/geom/Matrix","hilo/util/util"],function(t,e,i,r,n){var a=function(){function a(t,e,i){for(var r,n,a,o,s=0,h=!1,l=0,c=i.length;ld.x?(r=d.x,n=u.x):(r=u.x,n=d.x),t>=r&&t<=n))h=!0;else if(u.y>d.y?(a=d.y,o=u.y):(a=u.y,o=d.y),!(eo)){var f=(e-u.y)*(d.x-u.x)/(d.y-u.y)+u.x;if(f>t?s++:f==t&&(h=!0),u.x>t&&u.y==e){var p=i[(c+l-1)%c];(p.ye||p.y>e&&d.ys?s=c:cl?l=c:c=0)return!1;u>i.overlap&&(i.overlap=u,i.normal.x=p.x,i.normal.y=p.y)}return i}return e.create({Mixes:i,constructor:function(e){e=e||{},this.id=this.id||e.id||t.getUid("View"),n.copy(this,e,!0)},tint:16777215,id:null,x:0,y:0,width:0,height:0,alpha:1,rotation:0,visible:!0,pivotX:0,pivotY:0,scaleX:1,scaleY:1,pointerEnabled:!0,background:null,mask:null,align:null,drawable:null,boundsArea:null,parent:null,depth:-1,transform:null,blendMode:"source-over",getStage:function(){for(var t,e=this;t=e.parent;)e=t;return e.canvas?e:null},getScaledWidth:function(){return this.width*this.scaleX},getScaledHeight:function(){return this.height*this.scaleY},addTo:function(t,e){return"number"==typeof e?t.addChildAt(this,e):t.addChild(this),this},removeFromParent:function(){var t=this.parent;return t&&t.removeChild(this),this},getBounds:function(){for(var t,e,i,r,n,a,o,s=this.width,h=this.height,l=this.getConcatenatedMatrix(),c=this.boundsArea||[{x:0,y:0},{x:s,y:0},{x:s,y:h},{x:0,y:h}],u=[],d=0,f=c.length;de?r=e:ni?a=i:o>1,r=0;break;case"TR":i=o-n,r=0;break;case"L":i=0,r=s-a>>1;break;case"C":i=o-n>>1,r=s-a>>1;break;case"R":i=o-n,r=s-a>>1;break;case"BL":i=0,r=s-a;break;case"B":i=o-n>>1,r=s-a;break;case"BR":i=o-n,r=s-a}}return{x:i,y:r}},hitTestPoint:function(t,e,i){var r=this.getBounds(),n=t>=r.x&&t<=r.x+r.width&&e>=r.y&&e<=r.y+r.height;return n&&i&&(n=a(t,e,r)),n},hitTestObject:function(t,e){var i=this.getBounds(),r=t.getBounds(),n=i.x<=r.x+r.width&&r.x<=i.x+i.width&&i.y<=r.y+r.height&&r.y<=i.y+i.height;return n&&e&&(n=o(i,r)),!!n},_render:function(t,e){this.onUpdate&&this.onUpdate(e)===!1||!t.startDraw(this)||(t.transform(this),this.render(t,e),t.endDraw(this))},_fireMouseEvent:function(t){if(t.eventCurrentTarget=this,this.fire(t),"mousemove"==t.type){if(!this.__mouseOver){this.__mouseOver=!0;var e=n.copy({},t);e.type="mouseover",this.fire(e)}}else"mouseout"==t.type&&(this.__mouseOver=!1);var i=this.parent;t._stopped||t._stopPropagationed||!i||("mouseout"==t.type||"touchout"==t.type?i.hitTestPoint(t.stageX,t.stageY,!0)||i._fireMouseEvent(t):i._fireMouseEvent(t))},onUpdate:null,render:function(t,e){t.draw(this)},toString:function(){return t.viewToString(this)}})}();return a}),define("hilo/view/CacheMixin",["hilo/view/Drawable","hilo/util/browser"],function(t,e){var i,r,n={_cacheDirty:!0,cache:function(t){(t||this._cacheDirty||!this.drawable)&&this.updateCache()},updateCache:function(){e.supportCanvas&&(i||(i=document.createElement("canvas"),r=i.getContext("2d")),i.width=this.width,i.height=this.height,this._draw(r),this.drawable=this.drawable||new t,this.drawable.init({image:i.toDataURL()}),this._cacheDirty=!1)},setCacheDirty:function(t){this._cacheDirty=t}};return n}),define("hilo/view/Container",["hilo/core/Hilo","hilo/core/Class","hilo/view/View"],function(t,e,i){var r=e.create({Extends:i,constructor:function(e){e=e||{},this.id=this.id||e.id||t.getUid("Container"),r.superclass.constructor.call(this,e),this.children?this._updateChildren():this.children=[]},children:null,pointerChildren:!0,clipChildren:!1,getNumChildren:function(){return this.children.length},addChildAt:function(t,e){var i=this.children,r=i.length,n=t.parent;e=e<0?0:e>r?r:e;var a=this.getChildIndex(t);if(a==e)return this;if(a>=0?(i.splice(a,1),e=e==r?r-1:e):n&&n.removeChild(t),i.splice(e,0,t),a<0)this._updateChildren(e);else{var o=a=e.length)return null;var i=e[t];if(i){if(!i.__renderer)for(var r=i;r=r.parent;){if(r.renderer){i.__renderer=r.renderer;break}if(r.__renderer){i.__renderer=r.__renderer;break}}i.__renderer&&i.__renderer.remove(i),i.parent=null,i.depth=-1}return e.splice(t,1),this._updateChildren(t),i},removeChild:function(t){return this.removeChildAt(this.getChildIndex(t))},removeChildById:function(t){for(var e,i=this.children,r=0,n=i.length;r=e.length?null:e[t]},getChildById:function(t){for(var e,i=this.children,r=0,n=i.length;r=0&&r!=e){var n=i.length;e=e<0?0:e>=n?n-1:e,i.splice(r,1),i.splice(e,0,t),this._updateChildren()}return this},swapChildren:function(t,e){var i=this.children,r=this.getChildIndex(t),n=this.getChildIndex(e);t.depth=n,i[n]=t,e.depth=r,i[r]=e},swapChildrenAt:function(t,e){var i=this.children,r=this.getChildAt(t),n=this.getChildAt(e);r.depth=e,i[e]=r,n.depth=t,i[t]=n},sortChildren:function(t){var e=t,i=this.children;if("string"==typeof e){var r=e;e=function(t,e){return e[r]-t[r]}}i.sort(e),this._updateChildren()},_updateChildren:function(t,e){var i,r=this.children;t=t||0,e=e||r.length;for(var n=t;n=0;l--)if(a=h[l],!(!a||!a.visible||a.alpha<=0||n&&!a.pointerEnabled))if(a.children&&a.children.length&&(!n||a.pointerChildren)&&(o=a.getViewAtPoint(t,e,i,r,n)),o){if(!r)return o;o.length&&(s=s.concat(o))}else if(a.hitTestPoint(t,e,i)){if(!r)return a;s.push(a)}return r&&s.length?s:null},render:function(t,e){r.superclass.render.call(this,t,e);var i,n,a,o=this.children.slice(0);for(i=0,n=o.length;ir?r:e,i[e]=t,t.name&&(this._frameNames[t.name]=t),(0!=e||this.width)&&this.height||(this.width=t.rect[2],this.height=t.rect[3]),this},getFrame:function(t){if("number"==typeof t){var e=this._frames;return t<0||t>=e.length?null:e[t]}return this._frameNames[t]},getFrameIndex:function(t){var e=this._frames,i=e.length,r=-1;if("number"==typeof t)r=t;else{var n="string"==typeof t?this._frameNames[t]:t;if(n)for(var a=0;a=i?i-1:r,this.paused=e,this._firstRender=!0,this},_render:function(t,e){var i,r=this.currentFrame;if(this._firstRender?(i=r,this._firstRender=!1):i=this._nextFrame(e),i!=r){this.currentFrame=i;var a=this._frames[i].callback;a&&a.call(this)}this.onEnterFrame&&this.onEnterFrame(i),this.drawable.init(this._frames[i]),n.superclass._render.call(this,t,e)},_nextFrame:function(t){var e=this._frames,i=e.length,r=this.currentFrame,n=e[r],a=n.duration||this.interval,o=this._frameElapsed,s=0!=r||this.drawable?o+(this.timeBased?t:1):0;return o=this._frameElapsed=s=i-1)&&this.stop(),this.paused||0!=o||(null!=n.next?r=this.getFrameIndex(n.next):r>=i-1?r=0:this.drawable&&r++),r},setFrameCallback:function(t,e){return t=this.getFrame(t),t&&(t.callback=e),this},onEnterFrame:null});return n}),define("hilo/view/DOMElement",["hilo/core/Hilo","hilo/core/Class","hilo/view/View","hilo/view/Drawable"],function(t,e,i,r){var n=e.create({Extends:i,constructor:function(e){e=e||{},this.id=this.id||e.id||t.getUid("DOMElement"),n.superclass.constructor.call(this,e),this.drawable=new r;var i=this.drawable.domElement=e.element||t.createElement("div");i.id=this.id,this.pointerEnabled&&!i.style.pointerEvents&&(i.style.pointerEvents="visible")},_render:function(t,e){this.onUpdate&&this.onUpdate(e)===!1||(t.transform(this),this.visible&&this.alpha>0&&this.render(t,e))},render:function(e,i){if("dom"!==e.renderType){var r=e.canvas,n=this.parent,a=e._domElementContainer;e._domElementContainer||(a=e._domElementContainer=t.createElement("div",{style:{position:"absolute",transform:"scale3d("+n.scaleX+","+n.scaleY+", 1)",transformOrigin:"0 0",zIndex:"1"}}),r.parentNode.insertBefore(e._domElementContainer,r.nextSibling));var o,s=this.drawable.domElement,h=this.depth,l=a.childNodes[0];if(s.parentNode)return;for(;l&&3!=l.nodeType&&(o=parseInt(l.style.zIndex)||0,!(o<=0||o>h));)l=l.nextSibling;a.insertBefore(this.drawable.domElement,l)}else e.draw(this)}});return n}),define("hilo/view/Graphics",["hilo/core/Hilo","hilo/core/Class","hilo/view/View","hilo/view/CacheMixin"],function(t,e,i,r){var n=function(){var a=document.createElement("canvas"),o=a.getContext&&a.getContext("2d");return e.create({Extends:i,Mixes:r,constructor:function(e){e=e||{},this.id=this.id||e.id||t.getUid("Graphics"),n.superclass.constructor.call(this,e),this._actions=[]},lineWidth:1,lineAlpha:1,lineCap:null,lineJoin:null,miterLimit:10,hasStroke:!1,strokeStyle:"0",hasFill:!1,fillStyle:"0",fillAlpha:0,lineStyle:function(t,e,i,r,n,a){var o=this,s=o._addAction;return s.call(o,["lineWidth",o.lineWidth=t||1]),s.call(o,["strokeStyle",o.strokeStyle=e||"0"]),s.call(o,["lineAlpha",o.lineAlpha=i||1]),void 0!=r&&s.call(o,["lineCap",o.lineCap=r]),void 0!=n&&s.call(o,["lineJoin",o.lineJoin=n]),void 0!=a&&s.call(o,["miterLimit",o.miterLimit=a]),o.hasStroke=!0,o},setLineDash:function(t){return this._addAction(["setLineDash",t])},beginFill:function(t,e){var i=this,r=i._addAction;return r.call(i,["fillStyle",i.fillStyle=t]),r.call(i,["fillAlpha",i.fillAlpha=e||1]),i.hasFill=!0,i},endFill:function(){var t=this,e=t._addAction;return t.hasStroke&&e.call(t,["stroke"]),t.hasFill&&e.call(t,["fill"]),t.setCacheDirty(!0),t},beginLinearGradientFill:function(t,e,i,r,n,a){for(var s=this,h=o.createLinearGradient(t,e,i,r),l=0,c=n.length;l1?a.slice(1):null;"function"==typeof t[o]?t[o].apply(t,s):t[o]=a[1]}},render:function(t,e){var i=this;"canvas"===t.renderType?i._draw(t.context):(i.cache(),t.draw(i))},clear:function(){var t=this;return t._actions.length=0,t.lineWidth=1,t.lineAlpha=1,t.lineCap=null,t.lineJoin=null,t.miterLimit=10,t.hasStroke=!1,t.strokeStyle="0",t.hasFill=!1,t.fillStyle="0",t.fillAlpha=1,t.setCacheDirty(!0),t},_addAction:function(t){var e=this;return e._actions.push(t),e}})}();return n}),define("hilo/view/Text",["hilo/core/Class","hilo/core/Hilo","hilo/view/View","hilo/view/CacheMixin"],function(t,e,i,r){var n=t.create({Extends:i,Mixes:r,constructor:function(t){t=t||{},this.id=this.id||t.id||e.getUid("Text"),n.superclass.constructor.call(this,t),t.font||(this.font="12px arial"),this._fontHeight=n.measureFontHeight(this.font)},text:"",color:"#000",textAlign:null,textVAlign:null,outline:!1,lineSpacing:0,maxWidth:200,font:null,textWidth:0,textHeight:0,setFont:function(t){var e=this;return e.font!==t&&(e.font=t,e._fontHeight=n.measureFontHeight(t)),e},render:function(t,e){var i=this;if("canvas"===t.renderType)this.drawable?t.draw(i):i._draw(t.context);else if("dom"===t.renderType){var r=i.drawable,n=r.domElement,a=n.style;a.font=i.font,a.textAlign=i.textAlign,a.color=i.color,a.width=i.width+"px",a.height=i.height+"px",a.lineHeight=i._fontHeight+i.lineSpacing+"px",n.innerHTML=i.text,t.draw(this)}else i.cache(),t.draw(i)},_draw:function(t){var e=this,i=e.text.toString();if(i){t.font=e.font,t.textAlign=e.textAlign,t.textBaseline="top";var r,n,a,o,s,h=i.split(/\r\n|\r|\n|/),l=0,c=0,u=e._fontHeight+e.lineSpacing,d=[];for(r=0,o=h.length;re.maxWidth?(d.push({text:m,y:c}),l>1;break;case"bottom":_=e.height-e.textHeight}var x=e.background;for(x&&(t.fillStyle=x,t.fillRect(0,0,e.width,e.height)),e.outline?t.strokeStyle=e.color:t.fillStyle=e.color,r=0;r>1;break;case"right":case"end":n=a}r.outline?t.strokeText(e,n,i):t.fillText(e,n,i)},Statics:{measureFontHeight:function(t){var i,r=document.documentElement,n=e.createElement("div",{style:{font:t,position:"absolute"},innerHTML:"M"});return r.appendChild(n),i=n.offsetHeight,r.removeChild(n),i}}});return n}),define("hilo/view/BitmapText",["hilo/core/Class","hilo/core/Hilo","hilo/view/Container","hilo/view/Bitmap"],function(t,e,i,r){var n=t.create({Extends:i,constructor:function(t){t=t||{},this.id=this.id||t.id||e.getUid("BitmapText"),n.superclass.constructor.call(this,t);var i=t.text+"";i&&(this.text="",this.setText(i)),this.pointerChildren=!1},glyphs:null,letterSpacing:0,text:"",textAlign:"left",setText:function(t){var e=this,i=t.toString(),r=i.length;if(e.text!=i){e.text=i;var n,a,o,s,h=0,l=0,c=0;for(n=0;n0?e.letterSpacing:0),e.children[n]?(s=e.children[n],s.setImage(o.image,o.rect)):(s=e._createBitmap(o),e.addChild(s)),s.x=c,h=c+o.rect[2],l=Math.max(l,o.rect[3]));for(n=e.children.length-1;n>=r;n--)e._releaseBitmap(e.children[n]),e.children[n].removeFromParent();return e.width=h,e.height=l,this.setTextAlign(),e}},_createBitmap:function(t){var e;return n._pool.length?(e=n._pool.pop(),e.setImage(t.image,t.rect)):e=new r({image:t.image,rect:t.rect}),e},_releaseBitmap:function(t){n._pool.push(t)},setTextAlign:function(t){switch(this.textAlign=t||this.textAlign,this.textAlign){case"center":this.pivotX=.5*this.width;break;case"right":this.pivotX=this.width;break;case"left":default:this.pivotX=0}return this},hasGlyphs:function(t){var e=this.glyphs;if(!e)return!1;t=t.toString();var i,r=t.length;for(i=0;i=this._targetFPS?(this._measuredFPS=1e3/(this._tickTime/this._tickCount)+.5>>0,this._tickCount=0,this._tickTime=0):this._tickTime+=t-this._lastTime,this._lastTime=t;for(var r=i.slice(0),n=0,a=r.length;n=0&&e.splice(i,1)},nextTick:function(t){var e=this,i={tick:function(r){e.removeTick(i),t()}};return e.addTick(i),i},timeout:function(t,e){var i=this,r=(new Date).getTime()+e,n={tick:function(){var e=(new Date).getTime(),a=e-r;a>=0&&(i.removeTick(n),t())}};return i.addTick(n),n},interval:function(t,e){var i=this,r=(new Date).getTime()+e,n={tick:function(){var i=(new Date).getTime(),n=i-r;n>=0&&(n=r)return-1;for(e<0&&(e=r+e),i=e;i=1?1:s;var l=n.ease?n.ease(s):s;n.reverse&&n.isStart&&(n._reverseFlag<0&&(s=1-s,l=1-l),s<1e-7&&(n.repeat>0&&n._repeatCount++>=n.repeat||0==n.repeat&&!n.loop?h=!0:(n._startTime=i(),n._pausedTime=0,n._reverseFlag*=-1))),n.isStart||(n.setProps(n._fromProps,n._toProps),n.isStart=!0,n.onStart&&n.onStart.call(n,n)),n.time=a,n._render(l),(o=n.onUpdate)&&o.call(n,s,n),s>=1&&(n.reverse?(n._startTime=i(),n._pausedTime=0,n._reverseFlag*=-1):n.loop||n.repeat>0&&n._repeatCount++0&&u<=t?(c._render(s),c.time=a,e.add(c)):n.isComplete&&(u<0||u>t)&&c.start()}return n.isComplete?((o=n.onComplete)&&o.call(n,n),!0):void 0}}},Statics:{_tweens:[],tick:function(){var t,r,n=e._tweens,a=n.length;for(r=0;r-1&&n.splice(i,1);else for(i=0;i=i)return void t.fire("complete");if(t._currentIndexe.z})},tick:function(){this.sortZ()}});return o}();return i}),define("hilo/game/ParticleSystem",["hilo/core/Hilo","hilo/core/Class","hilo/view/View","hilo/view/Container","hilo/view/Drawable","hilo/util/util"],function(t,e,i,r,n,a){var o=function(){function o(t,e){return e?t+2*(Math.random()-.5)*e:t}for(var s=["x","y","vx","vy","ax","ay","rotation","rotationV","scale","scaleV","alpha","alphaV","life"],h=[],l=0,c=s.length;l=this._emitTime&&(this._currentRunTime=0,this._emitTime=o(this.emitTime,this.emitTimeVar),this._emit()),this._totalRunTime>=this.totalTime&&this.stop())},_emit:function(){for(var t=o(this.emitNum,this.emitNumVar)>>0,e=0;e=0;e--)this.children[e].destroy()}}),v=e.create({Extends:i,constructor:function(e){this.id=this.id||e.id||t.getUid("Particle"),v.superclass.constructor.call(this,e),this.init(e)},onUpdate:function(t){if(t*=.001,this._died)return!1;var e=this.ax+this.system.gx,i=this.ay+this.system.gy;return this.vx+=e*t,this.vy+=i*t,this.x+=this.vx*t,this.y+=this.vy*t,this.rotation+=this.rotationV,this._time>.1&&(this.alpha+=this.alphaV),this.scale+=this.scaleV,this.scaleX=this.scaleY=this.scale,this._time+=t,this._time>=this.life||this.alpha<=0?(this.destroy(),!1):void 0},setImage:function(t,e){this.drawable=this.drawable||new n,e=e||[0,0,t.width,t.height],this.width=e[2],this.height=e[3],this.drawable.rect=e,this.drawable.image=t},destroy:function(){this._died=!0,this.alpha=0,this.removeFromParent(),f.push(this)},init:function(t){this.system=t.system,this._died=!1,this._time=0,this.alpha=1;for(var e=0,i=h.length;e>0]),this.setImage(t.image,a),void 0!==t.pivotX&&(this.pivotX=t.pivotX*a[2]),void 0!==t.pivotY&&(this.pivotY=t.pivotY*a[3])}},Statics:{create:function(t){if(f.length>0){var e=f.pop();return e.init(t),e}return new v(t)}}});return p}();return o}); \ No newline at end of file +define("hilo/util/browser",function(){var t=function(){var t=navigator.userAgent,e=document,i=window,r=e.documentElement,n={iphone:/iphone/i.test(t),ipad:/ipad/i.test(t),ipod:/ipod/i.test(t),ios:/iphone|ipad|ipod/i.test(t),android:/android/i.test(t),webkit:/webkit/i.test(t),chrome:/chrome/i.test(t),safari:/safari/i.test(t),firefox:/firefox/i.test(t),ie:/msie/i.test(t),opera:/opera/i.test(t),supportTouch:"ontouchstart"in i,supportCanvas:null!=e.createElement("canvas").getContext,supportStorage:!1,supportOrientation:"orientation"in i||"orientation"in i.screen,supportDeviceMotion:"ondevicemotion"in i};try{var a="hilo";localStorage.setItem(a,a),localStorage.removeItem(a),n.supportStorage=!0}catch(o){}var s=n.jsVendor=n.webkit?"webkit":n.firefox?"webkit":n.opera?"o":n.ie?"ms":"",h=n.cssVendor="-"+s+"-",l=e.createElement("div"),c=l.style,u=void 0!=c[s+"Transform"],d=void 0!=c[s+"Perspective"];d&&(l.id="test3d",c=e.createElement("style"),c.textContent="@media ("+h+"transform-3d){#test3d{height:3px}}",e.head.appendChild(c),r.appendChild(l),d=3==l.offsetHeight,e.head.removeChild(c),r.removeChild(l)),n.supportTransform=u,n.supportTransform3D=d;var f=n.supportTouch,p=f?"touchstart":"mousedown",v=f?"touchmove":"mousemove",m=f?"touchend":"mouseup";return n.POINTER_START=p,n.POINTER_MOVE=v,n.POINTER_END=m,n}();return t}),define("hilo/util/util",function(){var t={copy:function(t,e,i){for(var r in e)i&&!t.hasOwnProperty(r)&&void 0===t[r]||(t[r]=e[r]);return t}};return t}),define("hilo/core/Hilo",["hilo/util/browser","hilo/util/util"],function(t,e){var i=window,r=document,n=r.documentElement,a=0,o={},s={version:"1.6.0",getUid:function(t){var e=++a;if(t){var i=t.charCodeAt(t.length-1);return i>=48&&i<=57&&(t+="_"),t+e}return e},viewToString:function(t){for(var e,i=t;i;)e=e?i.id+"."+e:i.id,i=i.parent;return e},copy:function(t,i,r){return e.copy(t,i,r),o.copy||(o.copy=!0,console.warn("Hilo.copy has been Deprecated! Use Hilo.util.copy instead.")),t},browser:t,event:{POINTER_START:t.POINTER_START,POINTER_MOVE:t.POINTER_MOVE,POINTER_END:t.POINTER_END},align:{TOP_LEFT:"TL",TOP:"T",TOP_RIGHT:"TR",LEFT:"L",CENTER:"C",RIGHT:"R",BOTTOM_LEFT:"BL",BOTTOM:"B",BOTTOM_RIGHT:"BR"},getElementRect:function(t){var e;try{e=t.getBoundingClientRect()}catch(r){e={top:t.offsetTop,left:t.offsetLeft,right:t.offsetLeft+t.offsetWidth,bottom:t.offsetTop+t.offsetHeight}}var a=(i.pageXOffset||n.scrollLeft)-(n.clientLeft||0)||0,o=(i.pageYOffset||n.scrollTop)-(n.clientTop||0)||0,s=i.getComputedStyle?getComputedStyle(t):t.currentStyle,h=parseInt,l=h(s.paddingLeft)+h(s.borderLeftWidth)||0,c=h(s.paddingTop)+h(s.borderTopWidth)||0,u=h(s.paddingRight)+h(s.borderRightWidth)||0,d=h(s.paddingBottom)+h(s.borderBottomWidth)||0,f=e.top||0,p=e.left||0,v=e.right||0,m=e.bottom||0;return{left:p+a+l,top:f+o+c,width:v-u-p-l,height:m-d-f-c}},createElement:function(t,e){var i,n,a,o=r.createElement(t);for(i in e)if(n=e[i],"style"===i)for(a in n)o.style[a]=n[a];else o[i]=n;return o},getElement:function(t){return r.getElementById(t)},setElementStyleByView:function(t){var e=t.drawable,i=e.domElement.style,r=t._stateCache||(t._stateCache={}),n=s.browser.jsVendor,a="px",o=!1;if(this.cacheStateIfChanged(t,["visible"],r)&&(i.display=t.visible?"":"none"),this.cacheStateIfChanged(t,["alpha"],r)&&(i.opacity=t.alpha),t.visible&&!(t.alpha<=0)){if(this.cacheStateIfChanged(t,["width"],r)&&(i.width=t.width+a),this.cacheStateIfChanged(t,["height"],r)&&(i.height=t.height+a),this.cacheStateIfChanged(t,["depth"],r)&&(i.zIndex=t.depth+1),t.transform){var h=t.transform;(o=this.cacheStateIfChanged(t,["pivotX","pivotY"],r))&&(i[n+"TransformOrigin"]="0 0"),i[n+"Transform"]="matrix3d("+h.a+", "+h.b+", 0, 0, "+h.c+", "+h.d+", 0, 0, 0, 0, 1, 0, "+h.tx+", "+h.ty+", 0, 1)"}else(o=this.cacheStateIfChanged(t,["pivotX","pivotY"],r))&&(i[n+"TransformOrigin"]=t.pivotX+a+" "+t.pivotY+a),(this.cacheStateIfChanged(t,["x","y","rotation","scaleX","scaleY"],r)||o)&&(i[n+"Transform"]=this.getTransformCSS(t));this.cacheStateIfChanged(t,["background"],r)&&(i.backgroundColor=t.background),i.pointerEvents||(i.pointerEvents="none");var l=e.image;if(l){var c=l.src;c!==r.image&&(r.image=c,i.backgroundImage="url("+c+")");var u=e.rect;if(u){var d=u[0],f=u[1];d!==r.sx&&(r.sx=d,i.backgroundPositionX=-d+a),f!==r.sy&&(r.sy=f,i.backgroundPositionY=-f+a)}}var p=t.mask;if(p){var v=p.drawable.domElement.style.backgroundImage;v!==r.maskImage&&(r.maskImage=v,i[n+"MaskImage"]=v,i[n+"MaskRepeat"]="no-repeat");var m=p.x,g=p.y;m===r.maskX&&g===r.maskY||(r.maskX=m,r.maskY=g,i[n+"MaskPosition"]=m+a+" "+g+a)}}},cacheStateIfChanged:function(t,e,i){var r,n,a,o,s=!1;for(r=0,n=e.length;r=6?(e=s[0],i=s[1],r=s[2],n=s[3],a=s[4],o=s[5]):(e=t.a,i=t.b,r=t.c,n=t.d,a=t.tx,o=t.ty),this.a=h*e+l*r,this.b=h*i+l*n,this.c=c*e+u*r,this.d=c*i+u*n,this.tx=d*e+f*r+a,this.ty=d*i+f*n+o,this},rotate:function(t){var e=Math.sin(t),i=Math.cos(t),r=this.a,n=this.b,a=this.c,o=this.d,s=this.tx,h=this.ty;return this.a=r*i-n*e,this.b=r*e+n*i,this.c=a*i-o*e,this.d=a*e+o*i,this.tx=s*i-h*e,this.ty=s*e+h*i,this},scale:function(t,e){return this.a*=t,this.d*=e,this.c*=t,this.b*=e,this.tx*=t,this.ty*=e,this},translate:function(t,e){return this.tx+=t,this.ty+=e,this},identity:function(){return this.a=this.d=1,this.b=this.c=this.tx=this.ty=0,this},invert:function(){var t=this.a,e=this.b,i=this.c,r=this.d,n=this.tx,a=t*r-e*i;return this.a=r/a,this.b=-e/a,this.c=-i/a,this.d=t/a,this.tx=(i*this.ty-r*n)/a,this.ty=-(t*this.ty-e*n)/a,this},transformPoint:function(t,e,i){var r=t.x*this.a+t.y*this.c+this.tx,n=t.x*this.b+t.y*this.d+this.ty;return e&&(r=r+.5>>0,n=n+.5>>0),i?{x:r,y:n}:(t.x=r,t.y=n,t)}});return e}),define("hilo/event/EventMixin",["hilo/core/Class"],function(t){var e={_listeners:null,on:function(t,e,i){for(var r=this._listeners=this._listeners||{},n=r[t]=r[t]||[],a=0,o=n.length;a-1&&o.splice(c,1)}}return 0==o.length&&delete a[n],!0}return!1}},i=t.create({constructor:function(t,e,i){this.type=t,this.target=e,this.detail=i,this.timeStamp=+new Date},type:null,target:null,detail:null,timeStamp:0,stopImmediatePropagation:function(){this._stopped=!0}}),r=window.Event;if(r){var n=r.prototype,a=n.stopImmediatePropagation;n.stopImmediatePropagation=function(){a&&a.call(this),this._stopped=!0}}return e}),define("hilo/view/Drawable",["hilo/core/Class","hilo/util/util"],function(t,e){var i=t.create({constructor:function(t){this.init(t)},image:null,rect:null,init:function(t){var r=this,n=r.image;i.isDrawable(t)?r.image=t:e.copy(r,t,!0);var a=r.image;if("string"==typeof a){if(!n||a!==n.getAttribute("src")){r.image=null;var o=new Image;return t.crossOrigin&&(o.crossOrigin="Anonymous"),o.onload=function(){o.onload=null,r.init(o)},void(o.src=a)}a=r.image=n}a&&!r.rect&&(r.rect=[0,0,a.width,a.height])},Statics:{isDrawable:function(t){if(!t||!t.tagName)return!1;var e=t.tagName.toLowerCase();return"img"===e||"canvas"===e||"video"===e}}});return i}),define("hilo/renderer/Renderer",["hilo/core/Class","hilo/util/util"],function(t,e){var i=t.create({constructor:function(t){t=t||{},e.copy(this,t,!0)},renderType:null,canvas:null,stage:null,blendMode:"source-over",startDraw:function(t){},draw:function(t){},endDraw:function(t){},transform:function(){},hide:function(){},remove:function(t){},clear:function(t,e,i,r){},resize:function(t,e){}});return i}),define("hilo/renderer/CanvasRenderer",["hilo/core/Class","hilo/core/Hilo","hilo/renderer/Renderer"],function(t,e,i){var r=t.create({Extends:i,constructor:function(t){r.superclass.constructor.call(this,t),this.context=this.canvas.getContext("2d")},renderType:"canvas",context:null,startDraw:function(t){return!!(t.visible&&t.alpha>0)&&(t===this.stage&&this.context.clearRect(0,0,t.width,t.height),t.blendMode!==this.blendMode&&(this.context.globalCompositeOperation=this.blendMode=t.blendMode),this.context.save(),!0)},draw:function(t){var e=this.context,i=t.width,r=t.height,n=t.background;n&&(e.fillStyle=n,e.fillRect(0,0,i,r));var a=t.drawable,o=a&&a.image;if(o){var s=a.rect,h=s[2],l=s[3],c=s[4],u=s[5];if(!h||!l)return;i||r||(i=t.width=h,r=t.height=l),(c||u)&&e.translate(c-.5*h,u-.5*l),e.drawImage(o,s[0],s[1],h,l,0,0,i,r)}},endDraw:function(t){this.context.restore()},transform:function(t){var i=t.drawable;if(i&&i.domElement)return void e.setElementStyleByView(t);var r=this.context,n=t.scaleX,a=t.scaleY;if(t===this.stage){var o=this.canvas.style,s=t._scaleX,h=t._scaleY,l=!1;(!s&&1!=n||s&&s!=n)&&(t._scaleX=n,o.width=n*t.width+"px",l=!0),(!h&&1!=a||h&&h!=a)&&(t._scaleY=a,o.height=a*t.height+"px",l=!0),l&&t.updateViewport()}else{var c=t.x,u=t.y,d=t.pivotX,f=t.pivotY,p=t.rotation%360,v=t.transform,m=t.mask;m&&(m._render(this),r.clip());var g=t.align;if(g){var _=t.getAlignPosition();c=_.x,u=_.y}v?r.transform(v.a,v.b,v.c,v.d,v.tx,v.ty):(0==c&&0==u||r.translate(c,u),0!=p&&r.rotate(p*Math.PI/180),1==n&&1==a||r.scale(n,a),0==d&&0==f||r.translate(-d,-f))}t.alpha>0&&(r.globalAlpha*=t.alpha)},remove:function(t){var e=t.drawable,i=e&&e.domElement;if(i){var r=i.parentNode;r&&r.removeChild(i)}},clear:function(t,e,i,r){this.context.clearRect(t,e,i,r)},resize:function(t,e){var i=this.canvas,r=this.stage,n=i.style;i.width=t,i.height=e,n.width=r.width*r.scaleX+"px",n.height=r.height*r.scaleY+"px"}});return r}),define("hilo/renderer/DOMRenderer",["hilo/core/Class","hilo/core/Hilo","hilo/renderer/Renderer","hilo/view/Drawable"],function(t,e,i,r){var n=function(){function a(t,i){var r=t.tagName||"div",n=i.image,a=t.width||n&&n.width,o=t.height||n&&n.height,s=e.createElement(r),h=s.style;if(t.id&&(s.id=t.id),h.position="absolute",h.left=(t.left||0)+"px",h.top=(t.top||0)+"px",h.width=a+"px",h.height=o+"px","canvas"==r){if(s.width=a,s.height=o,n){var l=s.getContext("2d"),c=i.rect||[0,0,a,o];l.drawImage(n,c[0],c[1],c[2],c[3],t.x||0,t.y||0,t.width||c[2],t.height||c[3])}}else if(h.opacity=void 0!=t.alpha?t.alpha:1,(t===this.stage||t.clipChildren)&&(h.overflow="hidden"),n&&n.src){h.backgroundImage="url("+n.src+")";var u=t.rectX||0,d=t.rectY||0;h.backgroundPosition=-u+"px "+-d+"px"}return s}return t.create({Extends:i,constructor:function(t){n.superclass.constructor.call(this,t)},renderType:"dom",startDraw:function(t){var e=t.drawable=t.drawable||new r;return e.domElement=e.domElement||a(t,e),!0},draw:function(t){var e=t.parent,i=t.drawable.domElement,r=i.parentNode;if(e){var n=e.drawable.domElement;if(n!=r&&n.appendChild(i),!t.width&&!t.height){var a=t.drawable.rect;a&&(a[2]||a[3])&&(t.width=a[2],t.height=a[3])}}else t!==this.stage||r||(i.style.overflow="hidden",this.canvas.appendChild(i))},transform:function(t){if(e.setElementStyleByView(t),t===this.stage){var i=this.canvas.style,r=t._scaleX,n=t._scaleY,a=t.scaleX,o=t.scaleY;(!r&&1!=a||r&&r!=a)&&(t._scaleX=a,i.width=a*t.width+"px"),(!n&&1!=o||n&&n!=o)&&(t._scaleY=o,i.height=o*t.height+"px")}},remove:function(t){var e=t.drawable,i=e&&e.domElement;if(i){var r=i.parentNode;r&&r.removeChild(i)}},hide:function(t){var e=t.drawable&&t.drawable.domElement;e&&(e.style.display="none")},resize:function(t,e){var i=this.canvas.style;i.width=t+"px",i.height=e+"px","absolute"!=i.position&&(i.position="relative")}})}();return n}),define("hilo/renderer/WebGLRenderer",["hilo/core/Class","hilo/core/Hilo","hilo/renderer/Renderer","hilo/geom/Matrix"],function(t,e,i,r){var n=Math.PI/180,a=t.create({Extends:i,Statics:{MAX_BATCH_NUM:2e3,ATTRIBUTE_NUM:5,isSupport:function(){if(void 0==this._isSupported){var t=document.createElement("canvas");t.getContext&&(t.getContext("webgl")||t.getContext("experimental-webgl"))?this._isSupported=!0:this._isSupported=!1}return this._isSupported},contextOptions:null},renderType:"webgl",gl:null,_isContextLost:!1,_cacheTexture:{},constructor:function(t){a.superclass.constructor.call(this,t);var e=this,i=a.contextOptions||{};this.gl=this.canvas.getContext("webgl",i)||this.canvas.getContext("experimental-webgl",i),this.maxBatchNum=a.MAX_BATCH_NUM,this.positionStride=4*a.ATTRIBUTE_NUM;var r=this.maxBatchNum*a.ATTRIBUTE_NUM*4,n=6*this.maxBatchNum;this.arrayBuffer=new ArrayBuffer(4*r),this.float32Array=new Float32Array(this.arrayBuffer),this.uint32Array=new Uint32Array(this.arrayBuffer),this.indexs=new Uint16Array(n);for(var o=0,s=0;o0)&&(t===this.stage&&this.clear(),!0)},draw:function(t){var e=t.width,i=t.height,r=(t.background,t.drawable),n=r&&r.image;if(n){var a=r.rect,o=a[2],s=a[3];e||i||(e=t.width=o,i=t.height=s),this.batchIndex>=this.maxBatchNum&&this._renderBatches();var h=this._createVertexs(n,a[0],a[1],o,s,0,0,e,i),l=this.batchIndex*this.positionStride,c=this.float32Array,u=this.uint32Array,d=(t.tint>>16)+(65280&t.tint)+((255&t.tint)<<16)+(255*t.__webglRenderAlpha<<24);c[l+0]=h[0],c[l+1]=h[1],c[l+2]=h[2],c[l+3]=h[3],u[l+4]=d,c[l+5]=h[4],c[l+6]=h[5],c[l+7]=h[6],c[l+8]=h[7],u[l+9]=d,c[l+10]=h[8],c[l+11]=h[9],c[l+12]=h[10],c[l+13]=h[11],u[l+14]=d,c[l+15]=h[12],c[l+16]=h[13],c[l+17]=h[14],c[l+18]=h[15],u[l+19]=d;for(var f=t.__webglWorldMatrix,p=0;p<4;p++){var v=c[l+5*p],m=c[l+5*p+1];c[l+5*p]=f.a*v+f.c*m+f.tx,c[l+5*p+1]=f.b*v+f.d*m+f.ty}t.__textureImage=n,this.sprites[this.batchIndex++]=t}},endDraw:function(t){t===this.stage&&this._renderBatches()},transform:function(t){var i=t.drawable;if(i&&i.domElement)return void e.setElementStyleByView(t);var n=t.scaleX,a=t.scaleY;if(t===this.stage){var o=this.canvas.style,s=t._scaleX,h=t._scaleY,l=!1;(!s&&1!=n||s&&s!=n)&&(t._scaleX=n,o.width=n*t.width+"px",l=!0),(!h&&1!=a||h&&h!=a)&&(t._scaleY=a,o.height=a*t.height+"px",l=!0),l&&t.updateViewport(),t.__webglWorldMatrix=t.__webglWorldMatrix||new r(1,0,0,1,0,0)}else t.parent&&(t.__webglWorldMatrix=t.__webglWorldMatrix||new r(1,0,0,1,0,0),this._setConcatenatedMatrix(t,t.parent));t.alpha>0&&(t.parent&&t.parent.__webglRenderAlpha?t.__webglRenderAlpha=t.alpha*t.parent.__webglRenderAlpha:t.__webglRenderAlpha=t.alpha)},remove:function(t){var e=t.drawable,i=e&&e.domElement;if(i){var r=i.parentNode;r&&r.removeChild(i)}},clear:function(t,e,i,r){this.gl.clear(this.gl.COLOR_BUFFER_BIT)},resize:function(t,e){if(this.width!==t||this.height!==e){var i=this.canvas,r=this.stage,n=i.style;this.width=i.width=t,this.height=i.height=e,n.width=r.width*r.scaleX+"px",n.height=r.height*r.scaleY+"px",this.gl.viewport(0,0,t,e),this.canvasHalfWidth=.5*t,this.canvasHalfHeight=.5*e,this._uploadProjectionTransform(!0)}},_renderBatches:function(){var t=this.gl;t.bufferSubData(t.ARRAY_BUFFER,0,this.uint32Array.subarray(0,this.batchIndex*this.positionStride));for(var e=0,i=0,r=null,n=0;n0&&(i.bindTexture(i.TEXTURE_2D,this._getTexture(this.sprites[t])),i.drawElements(i.TRIANGLES,6*r,i.UNSIGNED_SHORT,6*t*2))},_uploadProjectionTransform:function(t){this._projectionTransformElements&&!t||(this._projectionTransformElements=new Float32Array([1/this.canvasHalfWidth,0,0,0,-1/this.canvasHalfHeight,0,-1,1,1])),this.gl.uniformMatrix3fv(this.u_projectionTransform,!1,this._projectionTransformElements)},_initShaders:function(){var t=" attribute vec2 a_position;\n attribute vec2 a_TexCoord;\n attribute vec4 a_tint;\n uniform mat3 u_projectionTransform;\n varying vec2 v_TexCoord;\n varying vec4 v_tint;\n void main(){\n gl_Position = vec4((u_projectionTransform * vec3(a_position, 1.0)).xy, 1.0, 1.0);\n v_TexCoord = a_TexCoord;\n v_tint = vec4(a_tint.rgb * a_tint.a, a_tint.a);\n }\n ",e="\n precision mediump float;\n uniform sampler2D u_Sampler;\n varying vec2 v_TexCoord;\n varying vec4 v_tint;\n void main(){\n gl_FragColor = texture2D(u_Sampler, v_TexCoord) * v_tint;\n }\n ";this.defaultShader=new o(this,{v:t,f:e},{attributes:["a_position","a_TexCoord","a_tint"],uniforms:["u_projectionTransform","u_Sampler"]})},_createVertexs:function(t,e,i,r,n,a,o,s,h){var l=this.__tempVertexs||[],c=t.width,u=t.height;r/=c,n/=u,e/=c,i/=u,s=s,h=h,a=a,o=o,r+e>1&&(r=1-e),n+i>1&&(n=1-i);var d=0;return l[d++]=a,l[d++]=o,l[d++]=e,l[d++]=i,l[d++]=a+s,l[d++]=o,l[d++]=e+r,l[d++]=i,l[d++]=a,l[d++]=o+h,l[d++]=e,l[d++]=i+n,l[d++]=a+s,l[d++]=o+h,l[d++]=e+r,l[d++]=i+n,l},_setConcatenatedMatrix:function(t,e){var i=t.__webglWorldMatrix,r=1,a=0,o=t.rotation%360,s=t.pivotX,h=t.pivotY,l=t.scaleX,c=t.scaleY,u=t.transform;if(u)i.copy(u);else{if(o){var d=o*n;r=Math.cos(d),a=Math.sin(d)}var f=t.getAlignPosition();i.a=r*l,i.b=a*l,i.c=-a*c,i.d=r*c,i.tx=f.x-i.a*s-i.c*h,i.ty=f.y-i.b*s-i.d*h}i.concat(e.__webglWorldMatrix)},_getTexture:function(t){var e=t.__textureImage,i=this._cacheTexture[e.src];return i||(i=this.activeShader.uploadTexture(e)),i}}),o=function(t,e,i){this.renderer=t,this.gl=t.gl,this.program=this._createProgram(this.gl,e.v,e.f),i=i||{},this.attributes=i.attributes||[],this.uniforms=i.uniforms||[]};return o.prototype={active:function(){var t=this,e=t.renderer,i=t.gl,r=t.program;r&&i&&(e.activeShader=t,i.useProgram(r),t.attributes.forEach(function(t){e[t]=i.getAttribLocation(r,t),i.enableVertexAttribArray(e[t])}),t.uniforms.forEach(function(t){e[t]=i.getUniformLocation(r,t)}),t.width===e.width&&t.height===e.height||(t.width=e.width,t.height=e.height,e._uploadProjectionTransform()))},uploadTexture:function(t){var e=this.gl,i=this.renderer,r=e.createTexture(),n=i.u_Sampler;return e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,r),e.pixelStorei(e.UNPACK_PREMULTIPLY_ALPHA_WEBGL,1),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,t),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.uniform1i(n,0),e.bindTexture(e.TEXTURE_2D,null),this.renderer._cacheTexture[t.src]=r,r},_createProgram:function(t,e,i){var r=this._createShader(t,t.VERTEX_SHADER,e),n=this._createShader(t,t.FRAGMENT_SHADER,i);if(!r||!n)return null;var a=t.createProgram();if(a){t.attachShader(a,r),t.attachShader(a,n),t.linkProgram(a),t.deleteShader(n),t.deleteShader(r);var o=t.getProgramParameter(a,t.LINK_STATUS);if(!o){var s=t.getProgramInfoLog(a);return console.log("Failed to link program: "+s),t.deleteProgram(a),null}}return a},_createShader:function(t,e,i){var r=t.createShader(e);if(r){t.shaderSource(r,i),t.compileShader(r);var n=t.getShaderParameter(r,t.COMPILE_STATUS);if(!n){var a=t.getShaderInfoLog(r);return console.log("Failed to compile shader: "+a),t.deleteShader(r),null}}return r}},a}),define("hilo/view/View",["hilo/core/Hilo","hilo/core/Class","hilo/event/EventMixin","hilo/geom/Matrix","hilo/util/util"],function(t,e,i,r,n){var a=function(){function a(t,e,i){for(var r,n,a,o,s=0,h=!1,l=0,c=i.length;ld.x?(r=d.x,n=u.x):(r=u.x,n=d.x),t>=r&&t<=n))h=!0;else if(u.y>d.y?(a=d.y,o=u.y):(a=u.y,o=d.y),!(eo)){var f=(e-u.y)*(d.x-u.x)/(d.y-u.y)+u.x;if(f>t?s++:f==t&&(h=!0),u.x>t&&u.y==e){var p=i[(c+l-1)%c];(p.ye||p.y>e&&d.ys?s=c:cl?l=c:c=0)return!1;u>i.overlap&&(i.overlap=u,i.normal.x=p.x,i.normal.y=p.y)}return i}return e.create({Mixes:i,constructor:function(e){e=e||{},this.id=this.id||e.id||t.getUid("View"),n.copy(this,e,!0)},tint:16777215,id:null,x:0,y:0,width:0,height:0,alpha:1,rotation:0,visible:!0,pivotX:0,pivotY:0,scaleX:1,scaleY:1,pointerEnabled:!0,background:null,mask:null,align:null,drawable:null,boundsArea:null,parent:null,depth:-1,transform:null,blendMode:"source-over",getStage:function(){for(var t,e=this;t=e.parent;)e=t;return e.canvas?e:null},getScaledWidth:function(){return this.width*this.scaleX},getScaledHeight:function(){return this.height*this.scaleY},addTo:function(t,e){return"number"==typeof e?t.addChildAt(this,e):t.addChild(this),this},removeFromParent:function(){var t=this.parent;return t&&t.removeChild(this),this},getBounds:function(){for(var t,e,i,r,n,a,o,s=this.width,h=this.height,l=this.getConcatenatedMatrix(),c=this.boundsArea||[{x:0,y:0},{x:s,y:0},{x:s,y:h},{x:0,y:h}],u=[],d=0,f=c.length;de?r=e:ni?a=i:o>1,r=0;break;case"TR":i=o-n,r=0;break;case"L":i=0,r=s-a>>1;break;case"C":i=o-n>>1,r=s-a>>1;break;case"R":i=o-n,r=s-a>>1;break;case"BL":i=0,r=s-a;break;case"B":i=o-n>>1,r=s-a;break;case"BR":i=o-n,r=s-a}}return{x:i,y:r}},hitTestPoint:function(t,e,i){var r=this.getBounds(),n=t>=r.x&&t<=r.x+r.width&&e>=r.y&&e<=r.y+r.height;return n&&i&&(n=a(t,e,r)),n},hitTestObject:function(t,e){var i=this.getBounds(),r=t.getBounds(),n=i.x<=r.x+r.width&&r.x<=i.x+i.width&&i.y<=r.y+r.height&&r.y<=i.y+i.height;return n&&e&&(n=o(i,r)),!!n},_render:function(t,e){this.onUpdate&&this.onUpdate(e)===!1||!t.startDraw(this)||(t.transform(this),this.render(t,e),t.endDraw(this))},_fireMouseEvent:function(t){if(t.eventCurrentTarget=this,this.fire(t),"mousemove"==t.type){if(!this.__mouseOver){this.__mouseOver=!0;var e=n.copy({},t);e.type="mouseover",this.fire(e)}}else"mouseout"==t.type&&(this.__mouseOver=!1);var i=this.parent;t._stopped||t._stopPropagationed||!i||("mouseout"==t.type||"touchout"==t.type?i.hitTestPoint(t.stageX,t.stageY,!0)||i._fireMouseEvent(t):i._fireMouseEvent(t))},onUpdate:null,render:function(t,e){t.draw(this)},toString:function(){return t.viewToString(this)}})}();return a}),define("hilo/view/CacheMixin",["hilo/view/Drawable","hilo/util/browser"],function(t,e){var i,r,n={_cacheDirty:!0,cache:function(t){(t||this._cacheDirty||!this.drawable)&&this.updateCache()},updateCache:function(){e.supportCanvas&&(i||(i=document.createElement("canvas"),r=i.getContext("2d")),i.width=this.width,i.height=this.height,this._draw(r),this.drawable=this.drawable||new t,this.drawable.init({image:i.toDataURL()}),this._cacheDirty=!1)},setCacheDirty:function(t){this._cacheDirty=t}};return n}),define("hilo/view/Container",["hilo/core/Hilo","hilo/core/Class","hilo/view/View"],function(t,e,i){var r=e.create({Extends:i,constructor:function(e){e=e||{},this.id=this.id||e.id||t.getUid("Container"),r.superclass.constructor.call(this,e),this.children?this._updateChildren():this.children=[]},children:null,pointerChildren:!0,clipChildren:!1,getNumChildren:function(){return this.children.length},addChildAt:function(t,e){var i=this.children,r=i.length,n=t.parent;e=e<0?0:e>r?r:e;var a=this.getChildIndex(t);if(a==e)return this;if(a>=0?(i.splice(a,1),e=e==r?r-1:e):n&&n.removeChild(t),i.splice(e,0,t),a<0)this._updateChildren(e);else{var o=a=e.length)return null;var i=e[t];if(i){if(!i.__renderer)for(var r=i;r=r.parent;){if(r.renderer){i.__renderer=r.renderer;break}if(r.__renderer){i.__renderer=r.__renderer;break}}i.__renderer&&i.__renderer.remove(i),i.parent=null,i.depth=-1}return e.splice(t,1),this._updateChildren(t),i},removeChild:function(t){return this.removeChildAt(this.getChildIndex(t))},removeChildById:function(t){for(var e,i=this.children,r=0,n=i.length;r=e.length?null:e[t]},getChildById:function(t){for(var e,i=this.children,r=0,n=i.length;r=0&&r!=e){var n=i.length;e=e<0?0:e>=n?n-1:e,i.splice(r,1),i.splice(e,0,t),this._updateChildren()}return this},swapChildren:function(t,e){var i=this.children,r=this.getChildIndex(t),n=this.getChildIndex(e);t.depth=n,i[n]=t,e.depth=r,i[r]=e},swapChildrenAt:function(t,e){var i=this.children,r=this.getChildAt(t),n=this.getChildAt(e);r.depth=e,i[e]=r,n.depth=t,i[t]=n},sortChildren:function(t){var e=t,i=this.children;if("string"==typeof e){var r=e;e=function(t,e){return e[r]-t[r]}}i.sort(e),this._updateChildren()},_updateChildren:function(t,e){var i,r=this.children;t=t||0,e=e||r.length;for(var n=t;n=0;l--)if(a=h[l],!(!a||!a.visible||a.alpha<=0||n&&!a.pointerEnabled))if(a.children&&a.children.length&&(!n||a.pointerChildren)&&(o=a.getViewAtPoint(t,e,i,r,n)),o){if(!r)return o;o.length&&(s=s.concat(o))}else if(a.hitTestPoint(t,e,i)){if(!r)return a;s.push(a)}return r&&s.length?s:null},render:function(t,e){r.superclass.render.call(this,t,e);var i,n,a,o=this.children.slice(0);for(i=0,n=o.length;ir?r:e,i[e]=t,t.name&&(this._frameNames[t.name]=t),(0!=e||this.width)&&this.height||(this.width=t.rect[2],this.height=t.rect[3]),this},getFrame:function(t){if("number"==typeof t){var e=this._frames;return t<0||t>=e.length?null:e[t]}return this._frameNames[t]},getFrameIndex:function(t){var e=this._frames,i=e.length,r=-1;if("number"==typeof t)r=t;else{var n="string"==typeof t?this._frameNames[t]:t;if(n)for(var a=0;a=i?i-1:r,this.paused=e,this._firstRender=!0,this},_render:function(t,e){var i,r=this.currentFrame;if(this._firstRender?(i=r,this._firstRender=!1):i=this._nextFrame(e),i!=r){this.currentFrame=i;var a=this._frames[i].callback;a&&a.call(this)}this.onEnterFrame&&this.onEnterFrame(i),this.drawable.init(this._frames[i]),n.superclass._render.call(this,t,e)},_nextFrame:function(t){var e=this._frames,i=e.length,r=this.currentFrame,n=e[r],a=n.duration||this.interval,o=this._frameElapsed,s=0!=r||this.drawable?o+(this.timeBased?t:1):0;return o=this._frameElapsed=s=i-1)&&this.stop(),this.paused||0!=o||(null!=n.next?r=this.getFrameIndex(n.next):r>=i-1?r=0:this.drawable&&r++),r},setFrameCallback:function(t,e){return t=this.getFrame(t),t&&(t.callback=e),this},onEnterFrame:null});return n}),define("hilo/view/DOMElement",["hilo/core/Hilo","hilo/core/Class","hilo/view/View","hilo/view/Drawable"],function(t,e,i,r){var n=e.create({Extends:i,constructor:function(e){e=e||{},this.id=this.id||e.id||t.getUid("DOMElement"),n.superclass.constructor.call(this,e),this.drawable=new r;var i=this.drawable.domElement=e.element||t.createElement("div");i.id=this.id,this.pointerEnabled&&!i.style.pointerEvents&&(i.style.pointerEvents="visible")},_render:function(t,e){this.onUpdate&&this.onUpdate(e)===!1||(t.transform(this),this.visible&&this.alpha>0&&this.render(t,e))},render:function(e,i){if("dom"!==e.renderType){var r=e.canvas,n=this.parent,a=e._domElementContainer;e._domElementContainer||(a=e._domElementContainer=t.createElement("div",{style:{position:"absolute",transform:"scale3d("+n.scaleX+","+n.scaleY+", 1)",transformOrigin:"0 0",zIndex:"1"}}),r.parentNode.insertBefore(e._domElementContainer,r.nextSibling));var o,s=this.drawable.domElement,h=this.depth,l=a.childNodes[0];if(s.parentNode)return;for(;l&&3!=l.nodeType&&(o=parseInt(l.style.zIndex)||0,!(o<=0||o>h));)l=l.nextSibling;a.insertBefore(this.drawable.domElement,l)}else e.draw(this)}});return n}),define("hilo/view/Graphics",["hilo/core/Hilo","hilo/core/Class","hilo/view/View","hilo/view/CacheMixin"],function(t,e,i,r){var n=function(){var a=document.createElement("canvas"),o=a.getContext&&a.getContext("2d");return e.create({Extends:i,Mixes:r,constructor:function(e){e=e||{},this.id=this.id||e.id||t.getUid("Graphics"),n.superclass.constructor.call(this,e),this._actions=[]},lineWidth:1,lineAlpha:1,lineCap:null,lineJoin:null,miterLimit:10,hasStroke:!1,strokeStyle:"0",hasFill:!1,fillStyle:"0",fillAlpha:0,lineStyle:function(t,e,i,r,n,a){var o=this,s=o._addAction;return s.call(o,["lineWidth",o.lineWidth=t||1]),s.call(o,["strokeStyle",o.strokeStyle=e||"0"]),s.call(o,["lineAlpha",o.lineAlpha=i||1]),void 0!=r&&s.call(o,["lineCap",o.lineCap=r]),void 0!=n&&s.call(o,["lineJoin",o.lineJoin=n]),void 0!=a&&s.call(o,["miterLimit",o.miterLimit=a]),o.hasStroke=!0,o},setLineDash:function(t){return this._addAction(["setLineDash",t])},beginFill:function(t,e){var i=this,r=i._addAction;return r.call(i,["fillStyle",i.fillStyle=t]),r.call(i,["fillAlpha",i.fillAlpha=e||1]),i.hasFill=!0,i},endFill:function(){var t=this,e=t._addAction;return t.hasStroke&&e.call(t,["stroke"]),t.hasFill&&e.call(t,["fill"]),t.setCacheDirty(!0),t},beginLinearGradientFill:function(t,e,i,r,n,a){for(var s=this,h=o.createLinearGradient(t,e,i,r),l=0,c=n.length;l1?a.slice(1):null;"function"==typeof t[o]?t[o].apply(t,s):t[o]=a[1]}},render:function(t,e){var i=this;"canvas"===t.renderType?i._draw(t.context):(i.cache(),t.draw(i))},clear:function(){var t=this;return t._actions.length=0,t.lineWidth=1,t.lineAlpha=1,t.lineCap=null,t.lineJoin=null,t.miterLimit=10,t.hasStroke=!1,t.strokeStyle="0",t.hasFill=!1,t.fillStyle="0",t.fillAlpha=1,t.setCacheDirty(!0),t},_addAction:function(t){var e=this;return e._actions.push(t),e}})}();return n}),define("hilo/view/Text",["hilo/core/Class","hilo/core/Hilo","hilo/view/View","hilo/view/CacheMixin"],function(t,e,i,r){var n=t.create({Extends:i,Mixes:r,constructor:function(t){t=t||{},this.id=this.id||t.id||e.getUid("Text"),n.superclass.constructor.call(this,t),t.font||(this.font="12px arial"),this._fontHeight=n.measureFontHeight(this.font)},text:"",color:"#000",textAlign:null,textVAlign:null,outline:!1,lineSpacing:0,maxWidth:200,font:null,textWidth:0,textHeight:0,setFont:function(t){var e=this;return e.font!==t&&(e.font=t,e._fontHeight=n.measureFontHeight(t)),e},render:function(t,e){var i=this;if("canvas"===t.renderType)this.drawable?t.draw(i):i._draw(t.context);else if("dom"===t.renderType){var r=i.drawable,n=r.domElement,a=n.style;a.font=i.font,a.textAlign=i.textAlign,a.color=i.color,a.width=i.width+"px",a.height=i.height+"px",a.lineHeight=i._fontHeight+i.lineSpacing+"px",n.innerHTML=i.text,t.draw(this)}else i.cache(),t.draw(i)},_draw:function(t){var e=this,i=e.text.toString();if(i){t.font=e.font,t.textAlign=e.textAlign,t.textBaseline="top";var r,n,a,o,s,h=i.split(/\r\n|\r|\n|/),l=0,c=0,u=e._fontHeight+e.lineSpacing,d=[];for(r=0,o=h.length;re.maxWidth?(d.push({text:m,y:c}),l>1;break;case"bottom":_=e.height-e.textHeight}var x=e.background;for(x&&(t.fillStyle=x,t.fillRect(0,0,e.width,e.height)),e.outline?t.strokeStyle=e.color:t.fillStyle=e.color,r=0;r>1;break;case"right":case"end":n=a}r.outline?t.strokeText(e,n,i):t.fillText(e,n,i)},Statics:{measureFontHeight:function(t){var i,r=document.documentElement,n=e.createElement("div",{style:{font:t,position:"absolute"},innerHTML:"M"});return r.appendChild(n),i=n.offsetHeight,r.removeChild(n),i}}});return n}),define("hilo/view/BitmapText",["hilo/core/Class","hilo/core/Hilo","hilo/view/Container","hilo/view/Bitmap"],function(t,e,i,r){var n=t.create({Extends:i,constructor:function(t){t=t||{},this.id=this.id||t.id||e.getUid("BitmapText"),n.superclass.constructor.call(this,t);var i=t.text+"";i&&(this.text="",this.setText(i)),this.pointerChildren=!1},glyphs:null,letterSpacing:0,text:"",textAlign:"left",setText:function(t){var e=this,i=t.toString(),r=i.length;if(e.text!=i){e.text=i;var n,a,o,s,h=0,l=0,c=0;for(n=0;n0?e.letterSpacing:0),e.children[n]?(s=e.children[n],s.setImage(o.image,o.rect)):(s=e._createBitmap(o),e.addChild(s)),s.x=c,h=c+o.rect[2],l=Math.max(l,o.rect[3]));for(n=e.children.length-1;n>=r;n--)e._releaseBitmap(e.children[n]),e.children[n].removeFromParent();return e.width=h,e.height=l,this.setTextAlign(),e}},_createBitmap:function(t){var e;return n._pool.length?(e=n._pool.pop(),e.setImage(t.image,t.rect)):e=new r({image:t.image,rect:t.rect}),e},_releaseBitmap:function(t){n._pool.push(t)},setTextAlign:function(t){switch(this.textAlign=t||this.textAlign,this.textAlign){case"center":this.pivotX=.5*this.width;break;case"right":this.pivotX=this.width;break;case"left":default:this.pivotX=0}return this},hasGlyphs:function(t){var e=this.glyphs;if(!e)return!1;t=t.toString();var i,r=t.length;for(i=0;i=this._targetFPS?(this._measuredFPS=1e3/(this._tickTime/this._tickCount)+.5>>0,this._tickCount=0,this._tickTime=0):this._tickTime+=t-this._lastTime,this._lastTime=t;for(var r=i.slice(0),n=0,a=r.length;n=0&&e.splice(i,1)},nextTick:function(t){var e=this,i={tick:function(r){e.removeTick(i),t()}};return e.addTick(i),i},timeout:function(t,e){var i=this,r=(new Date).getTime()+e,n={tick:function(){var e=(new Date).getTime(),a=e-r;a>=0&&(i.removeTick(n),t())}};return i.addTick(n),n},interval:function(t,e){var i=this,r=(new Date).getTime()+e,n={tick:function(){var i=(new Date).getTime(),n=i-r;n>=0&&(n=r)return-1;for(e<0&&(e=r+e),i=e;i=1?1:s;var l=n.ease?n.ease(s):s;n.reverse&&n.isStart&&(n._reverseFlag<0&&(s=1-s,l=1-l),s<1e-7&&(n.repeat>0&&n._repeatCount++>=n.repeat||0==n.repeat&&!n.loop?h=!0:(n._startTime=i(),n._pausedTime=0,n._reverseFlag*=-1))),n.isStart||(n.setProps(n._fromProps,n._toProps),n.isStart=!0,n.onStart&&n.onStart.call(n,n)),n.time=a,n._render(l),(o=n.onUpdate)&&o.call(n,s,n),s>=1&&(n.reverse?(n._startTime=i(),n._pausedTime=0,n._reverseFlag*=-1):n.loop||n.repeat>0&&n._repeatCount++0&&u<=t?(c._render(s),c.time=a,e.add(c)):n.isComplete&&(u<0||u>t)&&c.start()}return n.isComplete?((o=n.onComplete)&&o.call(n,n),!0):void 0}}},Statics:{_tweens:[],tick:function(){var t,r,n=e._tweens,a=n.length;for(r=0;r-1&&n.splice(i,1);else for(i=0;i=i)return void t.fire("complete");if(t._currentIndexe.z})},tick:function(){this.sortZ()}});return o}();return i}),define("hilo/game/ParticleSystem",["hilo/core/Hilo","hilo/core/Class","hilo/view/View","hilo/view/Container","hilo/view/Drawable","hilo/util/util"],function(t,e,i,r,n,a){var o=function(){function o(t,e){return e?t+2*(Math.random()-.5)*e:t}for(var s=["x","y","vx","vy","ax","ay","rotation","rotationV","scale","scaleV","alpha","alphaV","life"],h=[],l=0,c=s.length;l=this._emitTime&&(this._currentRunTime=0,this._emitTime=o(this.emitTime,this.emitTimeVar),this._emit()),this._totalRunTime>=this.totalTime&&this.stop())},_emit:function(){for(var t=o(this.emitNum,this.emitNumVar)>>0,e=0;e=0;e--)this.children[e].destroy()}}),v=e.create({Extends:i,constructor:function(e){this.id=this.id||e.id||t.getUid("Particle"),v.superclass.constructor.call(this,e),this.init(e)},onUpdate:function(t){if(t*=.001,this._died)return!1;var e=this.ax+this.system.gx,i=this.ay+this.system.gy;return this.vx+=e*t,this.vy+=i*t,this.x+=this.vx*t,this.y+=this.vy*t,this.rotation+=this.rotationV,this._time>.1&&(this.alpha+=this.alphaV),this.scale+=this.scaleV,this.scaleX=this.scaleY=this.scale,this._time+=t,this._time>=this.life||this.alpha<=0?(this.destroy(),!1):void 0},setImage:function(t,e){this.drawable=this.drawable||new n,e=e||[0,0,t.width,t.height],this.width=e[2],this.height=e[3],this.drawable.rect=e,this.drawable.image=t},destroy:function(){this._died=!0,this.alpha=0,this.removeFromParent(),f.push(this)},init:function(t){this.system=t.system,this._died=!1,this._time=0,this.alpha=1;for(var e=0,i=h.length;e>0]),this.setImage(t.image,a),void 0!==t.pivotX&&(this.pivotX=t.pivotX*a[2]),void 0!==t.pivotY&&(this.pivotY=t.pivotY*a[3])}},Statics:{create:function(t){if(f.length>0){var e=f.pop();return e.init(t),e}return new v(t)}}});return p}();return o}); \ No newline at end of file diff --git a/build/amd/hilo-amd.zip b/build/amd/hilo-amd.zip index 23a6fed6..8ba14e6c 100644 Binary files a/build/amd/hilo-amd.zip and b/build/amd/hilo-amd.zip differ diff --git a/build/amd/hilo/core/Class.js b/build/amd/hilo/core/Class.js index 5546d7d8..ec729cf2 100644 --- a/build/amd/hilo/core/Class.js +++ b/build/amd/hilo/core/Class.js @@ -1,5 +1,5 @@ /** - * Hilo 1.5.0 for amd + * Hilo 1.6.0 for amd * Copyright 2016 alibaba.com * Licensed under the MIT License */ diff --git a/build/amd/hilo/core/Class.min.js b/build/amd/hilo/core/Class.min.js index 695ff363..d0917456 100644 --- a/build/amd/hilo/core/Class.min.js +++ b/build/amd/hilo/core/Class.min.js @@ -1,5 +1,5 @@ /** - * Hilo 1.5.0 for amd + * Hilo 1.6.0 for amd * Copyright 2016 alibaba.com * Licensed under the MIT License */ diff --git a/build/amd/hilo/core/Hilo.js b/build/amd/hilo/core/Hilo.js index 52746133..0876c2c4 100644 --- a/build/amd/hilo/core/Hilo.js +++ b/build/amd/hilo/core/Hilo.js @@ -1,5 +1,5 @@ /** - * Hilo 1.5.0 for amd + * Hilo 1.6.0 for amd * Copyright 2016 alibaba.com * Licensed under the MIT License */ @@ -27,7 +27,7 @@ var Hilo = { * Hilo version * @type String */ - version: '1.5.0', + version: '1.6.0', /** * @language=en * Gets a globally unique id. Such as Stage1, Bitmap2 etc. diff --git a/build/amd/hilo/core/Hilo.min.js b/build/amd/hilo/core/Hilo.min.js index 94387098..7d265e5c 100644 --- a/build/amd/hilo/core/Hilo.min.js +++ b/build/amd/hilo/core/Hilo.min.js @@ -1,6 +1,6 @@ /** - * Hilo 1.5.0 for amd + * Hilo 1.6.0 for amd * Copyright 2016 alibaba.com * Licensed under the MIT License */ -define("hilo/core/Hilo",["hilo/util/browser","hilo/util/util"],function(t,e){var a=window,o=document,r=o.documentElement,n=0,i={},s={version:"1.5.0",getUid:function(t){var e=++n;if(t){var a=t.charCodeAt(t.length-1);return a>=48&&a<=57&&(t+="_"),t+e}return e},viewToString:function(t){for(var e,a=t;a;)e=e?a.id+"."+e:a.id,a=a.parent;return e},copy:function(t,a,o){return e.copy(t,a,o),i.copy||(i.copy=!0,console.warn("Hilo.copy has been Deprecated! Use Hilo.util.copy instead.")),t},browser:t,event:{POINTER_START:t.POINTER_START,POINTER_MOVE:t.POINTER_MOVE,POINTER_END:t.POINTER_END},align:{TOP_LEFT:"TL",TOP:"T",TOP_RIGHT:"TR",LEFT:"L",CENTER:"C",RIGHT:"R",BOTTOM_LEFT:"BL",BOTTOM:"B",BOTTOM_RIGHT:"BR"},getElementRect:function(t){var e;try{e=t.getBoundingClientRect()}catch(o){e={top:t.offsetTop,left:t.offsetLeft,right:t.offsetLeft+t.offsetWidth,bottom:t.offsetTop+t.offsetHeight}}var n=(a.pageXOffset||r.scrollLeft)-(r.clientLeft||0)||0,i=(a.pageYOffset||r.scrollTop)-(r.clientTop||0)||0,s=a.getComputedStyle?getComputedStyle(t):t.currentStyle,c=parseInt,h=c(s.paddingLeft)+c(s.borderLeftWidth)||0,f=c(s.paddingTop)+c(s.borderTopWidth)||0,d=c(s.paddingRight)+c(s.borderRightWidth)||0,l=c(s.paddingBottom)+c(s.borderBottomWidth)||0,g=e.top||0,p=e.left||0,m=e.right||0,T=e.bottom||0;return{left:p+n+h,top:g+i+f,width:m-d-p-h,height:T-l-g-f}},createElement:function(t,e){var a,r,n,i=o.createElement(t);for(a in e)if(r=e[a],"style"===a)for(n in r)i.style[n]=r[n];else i[a]=r;return i},getElement:function(t){return o.getElementById(t)},setElementStyleByView:function(t){var e=t.drawable,a=e.domElement.style,o=t._stateCache||(t._stateCache={}),r=s.browser.jsVendor,n="px",i=!1;if(this.cacheStateIfChanged(t,["visible"],o)&&(a.display=t.visible?"":"none"),this.cacheStateIfChanged(t,["alpha"],o)&&(a.opacity=t.alpha),t.visible&&!(t.alpha<=0)){if(this.cacheStateIfChanged(t,["width"],o)&&(a.width=t.width+n),this.cacheStateIfChanged(t,["height"],o)&&(a.height=t.height+n),this.cacheStateIfChanged(t,["depth"],o)&&(a.zIndex=t.depth+1),t.transform){var c=t.transform;(i=this.cacheStateIfChanged(t,["pivotX","pivotY"],o))&&(a[r+"TransformOrigin"]="0 0"),a[r+"Transform"]="matrix3d("+c.a+", "+c.b+", 0, 0, "+c.c+", "+c.d+", 0, 0, 0, 0, 1, 0, "+c.tx+", "+c.ty+", 0, 1)"}else(i=this.cacheStateIfChanged(t,["pivotX","pivotY"],o))&&(a[r+"TransformOrigin"]=t.pivotX+n+" "+t.pivotY+n),(this.cacheStateIfChanged(t,["x","y","rotation","scaleX","scaleY"],o)||i)&&(a[r+"Transform"]=this.getTransformCSS(t));this.cacheStateIfChanged(t,["background"],o)&&(a.backgroundColor=t.background),a.pointerEvents||(a.pointerEvents="none");var h=e.image;if(h){var f=h.src;f!==o.image&&(o.image=f,a.backgroundImage="url("+f+")");var d=e.rect;if(d){var l=d[0],g=d[1];l!==o.sx&&(o.sx=l,a.backgroundPositionX=-l+n),g!==o.sy&&(o.sy=g,a.backgroundPositionY=-g+n)}}var p=t.mask;if(p){var m=p.drawable.domElement.style.backgroundImage;m!==o.maskImage&&(o.maskImage=m,a[r+"MaskImage"]=m,a[r+"MaskRepeat"]="no-repeat");var T=p.x,u=p.y;T===o.maskX&&u===o.maskY||(o.maskX=T,o.maskY=u,a[r+"MaskPosition"]=T+n+" "+u+n)}}},cacheStateIfChanged:function(t,e,a){var o,r,n,i,s=!1;for(o=0,r=e.length;o=48&&a<=57&&(t+="_"),t+e}return e},viewToString:function(t){for(var e,a=t;a;)e=e?a.id+"."+e:a.id,a=a.parent;return e},copy:function(t,a,o){return e.copy(t,a,o),i.copy||(i.copy=!0,console.warn("Hilo.copy has been Deprecated! Use Hilo.util.copy instead.")),t},browser:t,event:{POINTER_START:t.POINTER_START,POINTER_MOVE:t.POINTER_MOVE,POINTER_END:t.POINTER_END},align:{TOP_LEFT:"TL",TOP:"T",TOP_RIGHT:"TR",LEFT:"L",CENTER:"C",RIGHT:"R",BOTTOM_LEFT:"BL",BOTTOM:"B",BOTTOM_RIGHT:"BR"},getElementRect:function(t){var e;try{e=t.getBoundingClientRect()}catch(o){e={top:t.offsetTop,left:t.offsetLeft,right:t.offsetLeft+t.offsetWidth,bottom:t.offsetTop+t.offsetHeight}}var n=(a.pageXOffset||r.scrollLeft)-(r.clientLeft||0)||0,i=(a.pageYOffset||r.scrollTop)-(r.clientTop||0)||0,s=a.getComputedStyle?getComputedStyle(t):t.currentStyle,c=parseInt,h=c(s.paddingLeft)+c(s.borderLeftWidth)||0,f=c(s.paddingTop)+c(s.borderTopWidth)||0,d=c(s.paddingRight)+c(s.borderRightWidth)||0,l=c(s.paddingBottom)+c(s.borderBottomWidth)||0,g=e.top||0,p=e.left||0,m=e.right||0,T=e.bottom||0;return{left:p+n+h,top:g+i+f,width:m-d-p-h,height:T-l-g-f}},createElement:function(t,e){var a,r,n,i=o.createElement(t);for(a in e)if(r=e[a],"style"===a)for(n in r)i.style[n]=r[n];else i[a]=r;return i},getElement:function(t){return o.getElementById(t)},setElementStyleByView:function(t){var e=t.drawable,a=e.domElement.style,o=t._stateCache||(t._stateCache={}),r=s.browser.jsVendor,n="px",i=!1;if(this.cacheStateIfChanged(t,["visible"],o)&&(a.display=t.visible?"":"none"),this.cacheStateIfChanged(t,["alpha"],o)&&(a.opacity=t.alpha),t.visible&&!(t.alpha<=0)){if(this.cacheStateIfChanged(t,["width"],o)&&(a.width=t.width+n),this.cacheStateIfChanged(t,["height"],o)&&(a.height=t.height+n),this.cacheStateIfChanged(t,["depth"],o)&&(a.zIndex=t.depth+1),t.transform){var c=t.transform;(i=this.cacheStateIfChanged(t,["pivotX","pivotY"],o))&&(a[r+"TransformOrigin"]="0 0"),a[r+"Transform"]="matrix3d("+c.a+", "+c.b+", 0, 0, "+c.c+", "+c.d+", 0, 0, 0, 0, 1, 0, "+c.tx+", "+c.ty+", 0, 1)"}else(i=this.cacheStateIfChanged(t,["pivotX","pivotY"],o))&&(a[r+"TransformOrigin"]=t.pivotX+n+" "+t.pivotY+n),(this.cacheStateIfChanged(t,["x","y","rotation","scaleX","scaleY"],o)||i)&&(a[r+"Transform"]=this.getTransformCSS(t));this.cacheStateIfChanged(t,["background"],o)&&(a.backgroundColor=t.background),a.pointerEvents||(a.pointerEvents="none");var h=e.image;if(h){var f=h.src;f!==o.image&&(o.image=f,a.backgroundImage="url("+f+")");var d=e.rect;if(d){var l=d[0],g=d[1];l!==o.sx&&(o.sx=l,a.backgroundPositionX=-l+n),g!==o.sy&&(o.sy=g,a.backgroundPositionY=-g+n)}}var p=t.mask;if(p){var m=p.drawable.domElement.style.backgroundImage;m!==o.maskImage&&(o.maskImage=m,a[r+"MaskImage"]=m,a[r+"MaskRepeat"]="no-repeat");var T=p.x,u=p.y;T===o.maskX&&u===o.maskY||(o.maskX=T,o.maskY=u,a[r+"MaskPosition"]=T+n+" "+u+n)}}},cacheStateIfChanged:function(t,e,a){var o,r,n,i,s=!1;for(o=0,r=e.length;o=n)return void e.fire("complete");if(e._currentIndex=r)return void e.fire("complete");if(e._currentIndex=48&&i<=57&&(t+="_"),t+e}return e},viewToString:function(t){for(var e,i=t;i;)e=e?i.id+"."+e:i.id,i=i.parent;return e},copy:function(t,e,i){return n.copy(t,e,i),l.copy||(l.copy=!0,console.warn("Hilo.copy has been Deprecated! Use Hilo.util.copy instead.")),t},browser:r,event:{POINTER_START:r.POINTER_START,POINTER_MOVE:r.POINTER_MOVE,POINTER_END:r.POINTER_END},align:{TOP_LEFT:"TL",TOP:"T",TOP_RIGHT:"TR",LEFT:"L",CENTER:"C",RIGHT:"R",BOTTOM_LEFT:"BL",BOTTOM:"B",BOTTOM_RIGHT:"BR"},getElementRect:function(t){var e;try{e=t.getBoundingClientRect()}catch(i){e={top:t.offsetTop,left:t.offsetLeft,right:t.offsetLeft+t.offsetWidth,bottom:t.offsetTop+t.offsetHeight}}var r=(a.pageXOffset||s.scrollLeft)-(s.clientLeft||0)||0,n=(a.pageYOffset||s.scrollTop)-(s.clientTop||0)||0,o=a.getComputedStyle?getComputedStyle(t):t.currentStyle,h=parseInt,l=h(o.paddingLeft)+h(o.borderLeftWidth)||0,c=h(o.paddingTop)+h(o.borderTopWidth)||0,u=h(o.paddingRight)+h(o.borderRightWidth)||0,d=h(o.paddingBottom)+h(o.borderBottomWidth)||0,f=e.top||0,p=e.left||0,v=e.right||0,m=e.bottom||0;return{left:p+r+l,top:f+n+c,width:v-u-p-l,height:m-d-f-c}},createElement:function(t,e){var i,r,n,a=o.createElement(t);for(i in e)if(r=e[i],"style"===i)for(n in r)a.style[n]=r[n];else a[i]=r;return a},getElement:function(t){return o.getElementById(t)},setElementStyleByView:function(t){var e=t.drawable,i=e.domElement.style,r=t._stateCache||(t._stateCache={}),n=c.browser.jsVendor,a="px",o=!1;if(this.cacheStateIfChanged(t,["visible"],r)&&(i.display=t.visible?"":"none"),this.cacheStateIfChanged(t,["alpha"],r)&&(i.opacity=t.alpha),t.visible&&!(t.alpha<=0)){if(this.cacheStateIfChanged(t,["width"],r)&&(i.width=t.width+a),this.cacheStateIfChanged(t,["height"],r)&&(i.height=t.height+a),this.cacheStateIfChanged(t,["depth"],r)&&(i.zIndex=t.depth+1),t.transform){var s=t.transform;(o=this.cacheStateIfChanged(t,["pivotX","pivotY"],r))&&(i[n+"TransformOrigin"]="0 0"),i[n+"Transform"]="matrix3d("+s.a+", "+s.b+", 0, 0, "+s.c+", "+s.d+", 0, 0, 0, 0, 1, 0, "+s.tx+", "+s.ty+", 0, 1)"}else(o=this.cacheStateIfChanged(t,["pivotX","pivotY"],r))&&(i[n+"TransformOrigin"]=t.pivotX+a+" "+t.pivotY+a),(this.cacheStateIfChanged(t,["x","y","rotation","scaleX","scaleY"],r)||o)&&(i[n+"Transform"]=this.getTransformCSS(t));this.cacheStateIfChanged(t,["background"],r)&&(i.backgroundColor=t.background),i.pointerEvents||(i.pointerEvents="none");var h=e.image;if(h){var l=h.src;l!==r.image&&(r.image=l,i.backgroundImage="url("+l+")");var u=e.rect;if(u){var d=u[0],f=u[1];d!==r.sx&&(r.sx=d,i.backgroundPositionX=-d+a),f!==r.sy&&(r.sy=f,i.backgroundPositionY=-f+a)}}var p=t.mask;if(p){var v=p.drawable.domElement.style.backgroundImage;v!==r.maskImage&&(r.maskImage=v,i[n+"MaskImage"]=v,i[n+"MaskRepeat"]="no-repeat");var m=p.x,_=p.y;m===r.maskX&&_===r.maskY||(r.maskX=m,r.maskY=_,i[n+"MaskPosition"]=m+a+" "+_+a)}}},cacheStateIfChanged:function(t,e,i){var r,n,a,o,s=!1;for(r=0,n=e.length;r=6?(e=s[0],i=s[1],r=s[2],n=s[3],a=s[4],o=s[5]):(e=t.a,i=t.b,r=t.c,n=t.d,a=t.tx,o=t.ty),this.a=h*e+l*r,this.b=h*i+l*n,this.c=c*e+u*r,this.d=c*i+u*n,this.tx=d*e+f*r+a,this.ty=d*i+f*n+o,this},rotate:function(t){var e=Math.sin(t),i=Math.cos(t),r=this.a,n=this.b,a=this.c,o=this.d,s=this.tx,h=this.ty;return this.a=r*i-n*e,this.b=r*e+n*i,this.c=a*i-o*e,this.d=a*e+o*i,this.tx=s*i-h*e,this.ty=s*e+h*i,this},scale:function(t,e){return this.a*=t,this.d*=e,this.c*=t,this.b*=e,this.tx*=t,this.ty*=e,this},translate:function(t,e){return this.tx+=t,this.ty+=e,this},identity:function(){return this.a=this.d=1,this.b=this.c=this.tx=this.ty=0,this},invert:function(){var t=this.a,e=this.b,i=this.c,r=this.d,n=this.tx,a=t*r-e*i;return this.a=r/a,this.b=-e/a,this.c=-i/a,this.d=t/a,this.tx=(i*this.ty-r*n)/a,this.ty=-(t*this.ty-e*n)/a,this},transformPoint:function(t,e,i){var r=t.x*this.a+t.y*this.c+this.tx,n=t.x*this.b+t.y*this.d+this.ty;return e&&(r=r+.5>>0,n=n+.5>>0),i?{x:r,y:n}:(t.x=r,t.y=n,t)}});return n}),define(function(t,e,i){var r=t("hilo/core/Class"),n={_listeners:null,on:function(t,e,i){for(var r=this._listeners=this._listeners||{},n=r[t]=r[t]||[],a=0,o=n.length;a-1&&o.splice(c,1)}}return 0==o.length&&delete n[r],!0}return!1}},a=r.create({constructor:function(t,e,i){this.type=t,this.target=e,this.detail=i,this.timeStamp=+new Date},type:null,target:null,detail:null,timeStamp:0,stopImmediatePropagation:function(){this._stopped=!0}}),o=window.Event;if(o){var s=o.prototype,h=s.stopImmediatePropagation;s.stopImmediatePropagation=function(){h&&h.call(this),this._stopped=!0}}return n}),define(function(t,e,i){var r=t("hilo/core/Class"),n=t("hilo/util/util"),a=r.create({constructor:function(t){this.init(t)},image:null,rect:null,init:function(t){var e=this,i=e.image;a.isDrawable(t)?e.image=t:n.copy(e,t,!0);var r=e.image;if("string"==typeof r){if(!i||r!==i.getAttribute("src")){e.image=null;var o=new Image;return t.crossOrigin&&(o.crossOrigin="Anonymous"),o.onload=function(){o.onload=null,e.init(o)},void(o.src=r)}r=e.image=i}r&&!e.rect&&(e.rect=[0,0,r.width,r.height])},Statics:{isDrawable:function(t){if(!t||!t.tagName)return!1;var e=t.tagName.toLowerCase();return"img"===e||"canvas"===e||"video"===e}}});return a}),define(function(t,e,i){var r=t("hilo/core/Class"),n=t("hilo/util/util"),a=r.create({constructor:function(t){t=t||{},n.copy(this,t,!0)},renderType:null,canvas:null,stage:null,blendMode:"source-over",startDraw:function(t){},draw:function(t){},endDraw:function(t){},transform:function(){},hide:function(){},remove:function(t){},clear:function(t,e,i,r){},resize:function(t,e){}});return a}),define(function(t,e,i){var r=t("hilo/core/Class"),n=t("hilo/core/Hilo"),a=t("hilo/renderer/Renderer"),o=r.create({Extends:a,constructor:function(t){o.superclass.constructor.call(this,t),this.context=this.canvas.getContext("2d")},renderType:"canvas",context:null,startDraw:function(t){return!!(t.visible&&t.alpha>0)&&(t===this.stage&&this.context.clearRect(0,0,t.width,t.height),t.blendMode!==this.blendMode&&(this.context.globalCompositeOperation=this.blendMode=t.blendMode),this.context.save(),!0)},draw:function(t){var e=this.context,i=t.width,r=t.height,n=t.background;n&&(e.fillStyle=n,e.fillRect(0,0,i,r));var a=t.drawable,o=a&&a.image;if(o){var s=a.rect,h=s[2],l=s[3],c=s[4],u=s[5];if(!h||!l)return;i||r||(i=t.width=h,r=t.height=l),(c||u)&&e.translate(c-.5*h,u-.5*l),e.drawImage(o,s[0],s[1],h,l,0,0,i,r)}},endDraw:function(t){this.context.restore()},transform:function(t){var e=t.drawable;if(e&&e.domElement)return void n.setElementStyleByView(t);var i=this.context,r=t.scaleX,a=t.scaleY;if(t===this.stage){var o=this.canvas.style,s=t._scaleX,h=t._scaleY,l=!1;(!s&&1!=r||s&&s!=r)&&(t._scaleX=r,o.width=r*t.width+"px",l=!0),(!h&&1!=a||h&&h!=a)&&(t._scaleY=a,o.height=a*t.height+"px",l=!0),l&&t.updateViewport()}else{var c=t.x,u=t.y,d=t.pivotX,f=t.pivotY,p=t.rotation%360,v=t.transform,m=t.mask;m&&(m._render(this),i.clip());var _=t.align;if(_){var g=t.getAlignPosition();c=g.x,u=g.y}v?i.transform(v.a,v.b,v.c,v.d,v.tx,v.ty):(0==c&&0==u||i.translate(c,u),0!=p&&i.rotate(p*Math.PI/180),1==r&&1==a||i.scale(r,a),0==d&&0==f||i.translate(-d,-f))}t.alpha>0&&(i.globalAlpha*=t.alpha)},remove:function(t){var e=t.drawable,i=e&&e.domElement;if(i){var r=i.parentNode;r&&r.removeChild(i)}},clear:function(t,e,i,r){this.context.clearRect(t,e,i,r)},resize:function(t,e){var i=this.canvas,r=this.stage,n=i.style;i.width=t,i.height=e,n.width=r.width*r.scaleX+"px",n.height=r.height*r.scaleY+"px"}});return o}),define(function(t,e,i){var r=t("hilo/core/Class"),n=t("hilo/core/Hilo"),a=t("hilo/renderer/Renderer"),o=t("hilo/view/Drawable"),s=function(){function t(t,e){var i=t.tagName||"div",r=e.image,a=t.width||r&&r.width,o=t.height||r&&r.height,s=n.createElement(i),h=s.style;if(t.id&&(s.id=t.id),h.position="absolute",h.left=(t.left||0)+"px",h.top=(t.top||0)+"px",h.width=a+"px",h.height=o+"px","canvas"==i){if(s.width=a,s.height=o,r){var l=s.getContext("2d"),c=e.rect||[0,0,a,o];l.drawImage(r,c[0],c[1],c[2],c[3],t.x||0,t.y||0,t.width||c[2],t.height||c[3])}}else if(h.opacity=void 0!=t.alpha?t.alpha:1,(t===this.stage||t.clipChildren)&&(h.overflow="hidden"),r&&r.src){h.backgroundImage="url("+r.src+")";var u=t.rectX||0,d=t.rectY||0;h.backgroundPosition=-u+"px "+-d+"px"}return s}return r.create({Extends:a,constructor:function(t){s.superclass.constructor.call(this,t)},renderType:"dom",startDraw:function(e){var i=e.drawable=e.drawable||new o;return i.domElement=i.domElement||t(e,i),!0},draw:function(t){var e=t.parent,i=t.drawable.domElement,r=i.parentNode;if(e){var n=e.drawable.domElement;if(n!=r&&n.appendChild(i),!t.width&&!t.height){var a=t.drawable.rect;a&&(a[2]||a[3])&&(t.width=a[2],t.height=a[3])}}else t!==this.stage||r||(i.style.overflow="hidden",this.canvas.appendChild(i))},transform:function(t){if(n.setElementStyleByView(t),t===this.stage){var e=this.canvas.style,i=t._scaleX,r=t._scaleY,a=t.scaleX,o=t.scaleY;(!i&&1!=a||i&&i!=a)&&(t._scaleX=a,e.width=a*t.width+"px"),(!r&&1!=o||r&&r!=o)&&(t._scaleY=o,e.height=o*t.height+"px")}},remove:function(t){var e=t.drawable,i=e&&e.domElement;if(i){var r=i.parentNode;r&&r.removeChild(i)}},hide:function(t){var e=t.drawable&&t.drawable.domElement;e&&(e.style.display="none")},resize:function(t,e){var i=this.canvas.style;i.width=t+"px",i.height=e+"px","absolute"!=i.position&&(i.position="relative")}})}();return s}),define(function(t,e,i){var r=t("hilo/core/Class"),n=t("hilo/core/Hilo"),a=t("hilo/renderer/Renderer"),o=t("hilo/geom/Matrix"),s=Math.PI/180,h=r.create({Extends:a,Statics:{MAX_BATCH_NUM:2e3,ATTRIBUTE_NUM:5,isSupport:function(){if(void 0==this._isSupported){var t=document.createElement("canvas");t.getContext&&(t.getContext("webgl")||t.getContext("experimental-webgl"))?this._isSupported=!0:this._isSupported=!1}return this._isSupported},contextOptions:null},renderType:"webgl",gl:null,_isContextLost:!1,_cacheTexture:{},constructor:function(t){h.superclass.constructor.call(this,t);var e=this,i=h.contextOptions||{};this.gl=this.canvas.getContext("webgl",i)||this.canvas.getContext("experimental-webgl",i),this.maxBatchNum=h.MAX_BATCH_NUM,this.positionStride=4*h.ATTRIBUTE_NUM;var r=this.maxBatchNum*h.ATTRIBUTE_NUM*4,n=6*this.maxBatchNum;this.arrayBuffer=new ArrayBuffer(4*r),this.float32Array=new Float32Array(this.arrayBuffer),this.uint32Array=new Uint32Array(this.arrayBuffer),this.indexs=new Uint16Array(n);for(var a=0,o=0;a0)&&(t===this.stage&&this.clear(),!0)},draw:function(t){var e=t.width,i=t.height,r=(t.background,t.drawable),n=r&&r.image;if(n){var a=r.rect,o=a[2],s=a[3];e||i||(e=t.width=o,i=t.height=s),this.batchIndex>=this.maxBatchNum&&this._renderBatches();var h=this._createVertexs(n,a[0],a[1],o,s,0,0,e,i),l=this.batchIndex*this.positionStride,c=this.float32Array,u=this.uint32Array,d=(t.tint>>16)+(65280&t.tint)+((255&t.tint)<<16)+(255*t.__webglRenderAlpha<<24);c[l+0]=h[0],c[l+1]=h[1],c[l+2]=h[2],c[l+3]=h[3],u[l+4]=d,c[l+5]=h[4],c[l+6]=h[5],c[l+7]=h[6],c[l+8]=h[7],u[l+9]=d,c[l+10]=h[8],c[l+11]=h[9],c[l+12]=h[10],c[l+13]=h[11],u[l+14]=d,c[l+15]=h[12],c[l+16]=h[13],c[l+17]=h[14],c[l+18]=h[15],u[l+19]=d;for(var f=t.__webglWorldMatrix,p=0;p<4;p++){var v=c[l+5*p],m=c[l+5*p+1];c[l+5*p]=f.a*v+f.c*m+f.tx,c[l+5*p+1]=f.b*v+f.d*m+f.ty}t.__textureImage=n,this.sprites[this.batchIndex++]=t}},endDraw:function(t){t===this.stage&&this._renderBatches()},transform:function(t){var e=t.drawable;if(e&&e.domElement)return void n.setElementStyleByView(t);var i=t.scaleX,r=t.scaleY;if(t===this.stage){var a=this.canvas.style,s=t._scaleX,h=t._scaleY,l=!1;(!s&&1!=i||s&&s!=i)&&(t._scaleX=i,a.width=i*t.width+"px",l=!0),(!h&&1!=r||h&&h!=r)&&(t._scaleY=r,a.height=r*t.height+"px",l=!0),l&&t.updateViewport(),t.__webglWorldMatrix=t.__webglWorldMatrix||new o(1,0,0,1,0,0)}else t.parent&&(t.__webglWorldMatrix=t.__webglWorldMatrix||new o(1,0,0,1,0,0),this._setConcatenatedMatrix(t,t.parent));t.alpha>0&&(t.parent&&t.parent.__webglRenderAlpha?t.__webglRenderAlpha=t.alpha*t.parent.__webglRenderAlpha:t.__webglRenderAlpha=t.alpha)},remove:function(t){var e=t.drawable,i=e&&e.domElement;if(i){var r=i.parentNode;r&&r.removeChild(i)}},clear:function(t,e,i,r){this.gl.clear(this.gl.COLOR_BUFFER_BIT)},resize:function(t,e){if(this.width!==t||this.height!==e){var i=this.canvas,r=this.stage,n=i.style;this.width=i.width=t,this.height=i.height=e,n.width=r.width*r.scaleX+"px",n.height=r.height*r.scaleY+"px",this.gl.viewport(0,0,t,e),this.canvasHalfWidth=.5*t,this.canvasHalfHeight=.5*e,this._uploadProjectionTransform(!0)}},_renderBatches:function(){var t=this.gl;t.bufferSubData(t.ARRAY_BUFFER,0,this.uint32Array.subarray(0,this.batchIndex*this.positionStride));for(var e=0,i=0,r=null,n=0;n0&&(i.bindTexture(i.TEXTURE_2D,this._getTexture(this.sprites[t])),i.drawElements(i.TRIANGLES,6*r,i.UNSIGNED_SHORT,6*t*2))},_uploadProjectionTransform:function(t){this._projectionTransformElements&&!t||(this._projectionTransformElements=new Float32Array([1/this.canvasHalfWidth,0,0,0,-1/this.canvasHalfHeight,0,-1,1,1])),this.gl.uniformMatrix3fv(this.u_projectionTransform,!1,this._projectionTransformElements)},_initShaders:function(){var t=" attribute vec2 a_position;\n attribute vec2 a_TexCoord;\n attribute vec4 a_tint;\n uniform mat3 u_projectionTransform;\n varying vec2 v_TexCoord;\n varying vec4 v_tint;\n void main(){\n gl_Position = vec4((u_projectionTransform * vec3(a_position, 1.0)).xy, 1.0, 1.0);\n v_TexCoord = a_TexCoord;\n v_tint = vec4(a_tint.rgb * a_tint.a, a_tint.a);\n }\n ",e="\n precision mediump float;\n uniform sampler2D u_Sampler;\n varying vec2 v_TexCoord;\n varying vec4 v_tint;\n void main(){\n gl_FragColor = texture2D(u_Sampler, v_TexCoord) * v_tint;\n }\n ";this.defaultShader=new l(this,{v:t,f:e},{attributes:["a_position","a_TexCoord","a_tint"],uniforms:["u_projectionTransform","u_Sampler"]})},_createVertexs:function(t,e,i,r,n,a,o,s,h){var l=this.__tempVertexs||[],c=t.width,u=t.height;r/=c,n/=u,e/=c,i/=u,s=s,h=h,a=a,o=o,r+e>1&&(r=1-e),n+i>1&&(n=1-i);var d=0;return l[d++]=a,l[d++]=o,l[d++]=e,l[d++]=i,l[d++]=a+s,l[d++]=o,l[d++]=e+r,l[d++]=i,l[d++]=a,l[d++]=o+h,l[d++]=e,l[d++]=i+n,l[d++]=a+s,l[d++]=o+h,l[d++]=e+r,l[d++]=i+n,l},_setConcatenatedMatrix:function(t,e){var i=t.__webglWorldMatrix,r=1,n=0,a=t.rotation%360,o=t.pivotX,h=t.pivotY,l=t.scaleX,c=t.scaleY,u=t.transform;if(u)i.copy(u);else{if(a){var d=a*s;r=Math.cos(d),n=Math.sin(d)}var f=t.getAlignPosition();i.a=r*l,i.b=n*l,i.c=-n*c,i.d=r*c,i.tx=f.x-i.a*o-i.c*h,i.ty=f.y-i.b*o-i.d*h}i.concat(e.__webglWorldMatrix)},_getTexture:function(t){var e=t.__textureImage,i=this._cacheTexture[e.src];return i||(i=this.activeShader.uploadTexture(e)),i}}),l=function(t,e,i){this.renderer=t,this.gl=t.gl,this.program=this._createProgram(this.gl,e.v,e.f),i=i||{},this.attributes=i.attributes||[],this.uniforms=i.uniforms||[]};return l.prototype={active:function(){var t=this,e=t.renderer,i=t.gl,r=t.program;r&&i&&(e.activeShader=t,i.useProgram(r),t.attributes.forEach(function(t){e[t]=i.getAttribLocation(r,t),i.enableVertexAttribArray(e[t])}),t.uniforms.forEach(function(t){e[t]=i.getUniformLocation(r,t)}),t.width===e.width&&t.height===e.height||(t.width=e.width,t.height=e.height,e._uploadProjectionTransform()))},uploadTexture:function(t){var e=this.gl,i=this.renderer,r=e.createTexture(),n=i.u_Sampler;return e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,r),e.pixelStorei(e.UNPACK_PREMULTIPLY_ALPHA_WEBGL,1),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,t),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.uniform1i(n,0),e.bindTexture(e.TEXTURE_2D,null),this.renderer._cacheTexture[t.src]=r,r},_createProgram:function(t,e,i){var r=this._createShader(t,t.VERTEX_SHADER,e),n=this._createShader(t,t.FRAGMENT_SHADER,i);if(!r||!n)return null;var a=t.createProgram();if(a){t.attachShader(a,r),t.attachShader(a,n),t.linkProgram(a),t.deleteShader(n),t.deleteShader(r);var o=t.getProgramParameter(a,t.LINK_STATUS);if(!o){var s=t.getProgramInfoLog(a);return console.log("Failed to link program: "+s),t.deleteProgram(a),null}}return a},_createShader:function(t,e,i){var r=t.createShader(e);if(r){t.shaderSource(r,i),t.compileShader(r);var n=t.getShaderParameter(r,t.COMPILE_STATUS);if(!n){var a=t.getShaderInfoLog(r);return console.log("Failed to compile shader: "+a),t.deleteShader(r),null}}return r}},h}),define(function(t,e,i){var r=t("hilo/core/Hilo"),n=t("hilo/core/Class"),a=t("hilo/event/EventMixin"),o=t("hilo/geom/Matrix"),s=t("hilo/util/util"),h=function(){function t(t,e,i){for(var r,n,a,o,s=0,h=!1,l=0,c=i.length;ld.x?(r=d.x,n=u.x):(r=u.x,n=d.x),t>=r&&t<=n))h=!0;else if(u.y>d.y?(a=d.y,o=u.y):(a=u.y,o=d.y),!(eo)){var f=(e-u.y)*(d.x-u.x)/(d.y-u.y)+u.x;if(f>t?s++:f==t&&(h=!0),u.x>t&&u.y==e){var p=i[(c+l-1)%c];(p.ye||p.y>e&&d.ys?s=c:cl?l=c:c=0)return!1;u>i.overlap&&(i.overlap=u,i.normal.x=p.x,i.normal.y=p.y)}return i}return n.create({Mixes:a,constructor:function(t){t=t||{},this.id=this.id||t.id||r.getUid("View"),s.copy(this,t,!0)},tint:16777215,id:null,x:0,y:0,width:0,height:0,alpha:1,rotation:0,visible:!0,pivotX:0,pivotY:0,scaleX:1,scaleY:1,pointerEnabled:!0,background:null,mask:null,align:null,drawable:null,boundsArea:null,parent:null,depth:-1,transform:null,blendMode:"source-over",getStage:function(){for(var t,e=this;t=e.parent;)e=t;return e.canvas?e:null},getScaledWidth:function(){return this.width*this.scaleX},getScaledHeight:function(){return this.height*this.scaleY},addTo:function(t,e){return"number"==typeof e?t.addChildAt(this,e):t.addChild(this),this},removeFromParent:function(){var t=this.parent;return t&&t.removeChild(this),this},getBounds:function(){for(var t,e,i,r,n,a,o,s=this.width,h=this.height,l=this.getConcatenatedMatrix(),c=this.boundsArea||[{x:0,y:0},{x:s,y:0},{x:s,y:h},{x:0,y:h}],u=[],d=0,f=c.length;de?r=e:ni?a=i:o>1,r=0;break;case"TR":i=o-n,r=0;break;case"L":i=0,r=s-a>>1;break;case"C":i=o-n>>1,r=s-a>>1;break;case"R":i=o-n,r=s-a>>1;break;case"BL":i=0,r=s-a;break;case"B":i=o-n>>1,r=s-a;break;case"BR":i=o-n,r=s-a}}return{x:i,y:r}},hitTestPoint:function(e,i,r){var n=this.getBounds(),a=e>=n.x&&e<=n.x+n.width&&i>=n.y&&i<=n.y+n.height;return a&&r&&(a=t(e,i,n)),a},hitTestObject:function(t,i){var r=this.getBounds(),n=t.getBounds(),a=r.x<=n.x+n.width&&n.x<=r.x+r.width&&r.y<=n.y+n.height&&n.y<=r.y+r.height;return a&&i&&(a=e(r,n)),!!a},_render:function(t,e){this.onUpdate&&this.onUpdate(e)===!1||!t.startDraw(this)||(t.transform(this),this.render(t,e),t.endDraw(this))},_fireMouseEvent:function(t){if(t.eventCurrentTarget=this,this.fire(t),"mousemove"==t.type){if(!this.__mouseOver){this.__mouseOver=!0;var e=s.copy({},t);e.type="mouseover",this.fire(e)}}else"mouseout"==t.type&&(this.__mouseOver=!1);var i=this.parent;t._stopped||t._stopPropagationed||!i||("mouseout"==t.type||"touchout"==t.type?i.hitTestPoint(t.stageX,t.stageY,!0)||i._fireMouseEvent(t):i._fireMouseEvent(t))},onUpdate:null,render:function(t,e){t.draw(this)},toString:function(){return r.viewToString(this)}})}();return h}),define(function(t,e,i){var r,n,a=t("hilo/view/Drawable"),o=t("hilo/util/browser"),s={_cacheDirty:!0,cache:function(t){(t||this._cacheDirty||!this.drawable)&&this.updateCache()},updateCache:function(){o.supportCanvas&&(r||(r=document.createElement("canvas"),n=r.getContext("2d")),r.width=this.width,r.height=this.height,this._draw(n),this.drawable=this.drawable||new a,this.drawable.init({image:r.toDataURL()}),this._cacheDirty=!1)},setCacheDirty:function(t){this._cacheDirty=t}};return s}),define(function(t,e,i){var r=t("hilo/core/Hilo"),n=t("hilo/core/Class"),a=t("hilo/view/View"),o=n.create({Extends:a,constructor:function(t){t=t||{},this.id=this.id||t.id||r.getUid("Container"),o.superclass.constructor.call(this,t),this.children?this._updateChildren():this.children=[]},children:null,pointerChildren:!0,clipChildren:!1,getNumChildren:function(){return this.children.length},addChildAt:function(t,e){var i=this.children,r=i.length,n=t.parent;e=e<0?0:e>r?r:e;var a=this.getChildIndex(t);if(a==e)return this;if(a>=0?(i.splice(a,1),e=e==r?r-1:e):n&&n.removeChild(t),i.splice(e,0,t),a<0)this._updateChildren(e);else{var o=a=e.length)return null;var i=e[t];if(i){if(!i.__renderer)for(var r=i;r=r.parent;){if(r.renderer){i.__renderer=r.renderer;break}if(r.__renderer){i.__renderer=r.__renderer;break}}i.__renderer&&i.__renderer.remove(i),i.parent=null,i.depth=-1}return e.splice(t,1),this._updateChildren(t),i},removeChild:function(t){return this.removeChildAt(this.getChildIndex(t))},removeChildById:function(t){for(var e,i=this.children,r=0,n=i.length;r=e.length?null:e[t]},getChildById:function(t){for(var e,i=this.children,r=0,n=i.length;r=0&&r!=e){var n=i.length;e=e<0?0:e>=n?n-1:e,i.splice(r,1),i.splice(e,0,t),this._updateChildren()}return this},swapChildren:function(t,e){var i=this.children,r=this.getChildIndex(t),n=this.getChildIndex(e);t.depth=n,i[n]=t,e.depth=r,i[r]=e},swapChildrenAt:function(t,e){var i=this.children,r=this.getChildAt(t),n=this.getChildAt(e);r.depth=e,i[e]=r,n.depth=t,i[t]=n},sortChildren:function(t){var e=t,i=this.children;if("string"==typeof e){var r=e;e=function(t,e){return e[r]-t[r]}}i.sort(e),this._updateChildren()},_updateChildren:function(t,e){var i,r=this.children;t=t||0,e=e||r.length;for(var n=t;n=0;l--)if(a=h[l],!(!a||!a.visible||a.alpha<=0||n&&!a.pointerEnabled))if(a.children&&a.children.length&&(!n||a.pointerChildren)&&(o=a.getViewAtPoint(t,e,i,r,n)),o){if(!r)return o;o.length&&(s=s.concat(o))}else if(a.hitTestPoint(t,e,i)){if(!r)return a;s.push(a)}return r&&s.length?s:null},render:function(t,e){o.superclass.render.call(this,t,e);var i,r,n,a=this.children.slice(0);for(i=0,r=a.length;ir?r:e,i[e]=t,t.name&&(this._frameNames[t.name]=t),(0!=e||this.width)&&this.height||(this.width=t.rect[2],this.height=t.rect[3]),this},getFrame:function(t){if("number"==typeof t){var e=this._frames;return t<0||t>=e.length?null:e[t]}return this._frameNames[t]},getFrameIndex:function(t){var e=this._frames,i=e.length,r=-1;if("number"==typeof t)r=t;else{var n="string"==typeof t?this._frameNames[t]:t;if(n)for(var a=0;a=i?i-1:r,this.paused=e,this._firstRender=!0,this},_render:function(t,e){var i,r=this.currentFrame;if(this._firstRender?(i=r,this._firstRender=!1):i=this._nextFrame(e),i!=r){this.currentFrame=i;var n=this._frames[i].callback;n&&n.call(this)}this.onEnterFrame&&this.onEnterFrame(i),this.drawable.init(this._frames[i]),s.superclass._render.call(this,t,e)},_nextFrame:function(t){var e=this._frames,i=e.length,r=this.currentFrame,n=e[r],a=n.duration||this.interval,o=this._frameElapsed,s=0!=r||this.drawable?o+(this.timeBased?t:1):0;return o=this._frameElapsed=s=i-1)&&this.stop(),this.paused||0!=o||(null!=n.next?r=this.getFrameIndex(n.next):r>=i-1?r=0:this.drawable&&r++),r},setFrameCallback:function(t,e){return t=this.getFrame(t),t&&(t.callback=e),this},onEnterFrame:null});return s}),define(function(t,e,i){var r=t("hilo/core/Hilo"),n=t("hilo/core/Class"),a=t("hilo/view/View"),o=t("hilo/view/Drawable"),s=n.create({Extends:a,constructor:function(t){t=t||{},this.id=this.id||t.id||r.getUid("DOMElement"),s.superclass.constructor.call(this,t),this.drawable=new o;var e=this.drawable.domElement=t.element||r.createElement("div");e.id=this.id,this.pointerEnabled&&!e.style.pointerEvents&&(e.style.pointerEvents="visible")},_render:function(t,e){this.onUpdate&&this.onUpdate(e)===!1||(t.transform(this),this.visible&&this.alpha>0&&this.render(t,e))},render:function(t,e){if("dom"!==t.renderType){var i=t.canvas,n=this.parent,a=t._domElementContainer;t._domElementContainer||(a=t._domElementContainer=r.createElement("div",{style:{position:"absolute",transform:"scale3d("+n.scaleX+","+n.scaleY+", 1)",transformOrigin:"0 0",zIndex:"1"}}),i.parentNode.insertBefore(t._domElementContainer,i.nextSibling));var o,s=this.drawable.domElement,h=this.depth,l=a.childNodes[0];if(s.parentNode)return;for(;l&&3!=l.nodeType&&(o=parseInt(l.style.zIndex)||0,!(o<=0||o>h));)l=l.nextSibling;a.insertBefore(this.drawable.domElement,l)}else t.draw(this)}});return s}),define(function(t,e,i){var r=t("hilo/core/Hilo"),n=t("hilo/core/Class"),a=t("hilo/view/View"),o=t("hilo/view/CacheMixin"),s=function(){var t=document.createElement("canvas"),e=t.getContext&&t.getContext("2d");return n.create({Extends:a,Mixes:o,constructor:function(t){t=t||{},this.id=this.id||t.id||r.getUid("Graphics"),s.superclass.constructor.call(this,t),this._actions=[]},lineWidth:1,lineAlpha:1,lineCap:null,lineJoin:null,miterLimit:10,hasStroke:!1,strokeStyle:"0",hasFill:!1,fillStyle:"0",fillAlpha:0,lineStyle:function(t,e,i,r,n,a){var o=this,s=o._addAction;return s.call(o,["lineWidth",o.lineWidth=t||1]),s.call(o,["strokeStyle",o.strokeStyle=e||"0"]),s.call(o,["lineAlpha",o.lineAlpha=i||1]),void 0!=r&&s.call(o,["lineCap",o.lineCap=r]),void 0!=n&&s.call(o,["lineJoin",o.lineJoin=n]),void 0!=a&&s.call(o,["miterLimit",o.miterLimit=a]),o.hasStroke=!0,o},setLineDash:function(t){return this._addAction(["setLineDash",t])},beginFill:function(t,e){var i=this,r=i._addAction;return r.call(i,["fillStyle",i.fillStyle=t]),r.call(i,["fillAlpha",i.fillAlpha=e||1]),i.hasFill=!0,i},endFill:function(){var t=this,e=t._addAction;return t.hasStroke&&e.call(t,["stroke"]),t.hasFill&&e.call(t,["fill"]),t.setCacheDirty(!0),t},beginLinearGradientFill:function(t,i,r,n,a,o){for(var s=this,h=e.createLinearGradient(t,i,r,n),l=0,c=a.length;l1?a.slice(1):null;"function"==typeof t[o]?t[o].apply(t,s):t[o]=a[1]}},render:function(t,e){var i=this;"canvas"===t.renderType?i._draw(t.context):(i.cache(),t.draw(i))},clear:function(){var t=this;return t._actions.length=0,t.lineWidth=1,t.lineAlpha=1,t.lineCap=null,t.lineJoin=null,t.miterLimit=10,t.hasStroke=!1,t.strokeStyle="0",t.hasFill=!1,t.fillStyle="0",t.fillAlpha=1,t.setCacheDirty(!0),t},_addAction:function(t){var e=this;return e._actions.push(t),e}})}();return s}),define(function(t,e,i){var r=t("hilo/core/Class"),n=t("hilo/core/Hilo"),a=t("hilo/view/View"),o=t("hilo/view/CacheMixin"),s=r.create({Extends:a,Mixes:o,constructor:function(t){t=t||{},this.id=this.id||t.id||n.getUid("Text"),s.superclass.constructor.call(this,t),t.font||(this.font="12px arial"),this._fontHeight=s.measureFontHeight(this.font)},text:"",color:"#000",textAlign:null,textVAlign:null,outline:!1,lineSpacing:0,maxWidth:200,font:null,textWidth:0,textHeight:0,setFont:function(t){var e=this;return e.font!==t&&(e.font=t,e._fontHeight=s.measureFontHeight(t)),e},render:function(t,e){var i=this;if("canvas"===t.renderType)this.drawable?t.draw(i):i._draw(t.context);else if("dom"===t.renderType){var r=i.drawable,n=r.domElement,a=n.style;a.font=i.font,a.textAlign=i.textAlign,a.color=i.color,a.width=i.width+"px",a.height=i.height+"px",a.lineHeight=i._fontHeight+i.lineSpacing+"px",n.innerHTML=i.text,t.draw(this)}else i.cache(),t.draw(i)},_draw:function(t){var e=this,i=e.text.toString();if(i){t.font=e.font,t.textAlign=e.textAlign,t.textBaseline="top";var r,n,a,o,s,h=i.split(/\r\n|\r|\n|/),l=0,c=0,u=e._fontHeight+e.lineSpacing,d=[];for(r=0,o=h.length;re.maxWidth?(d.push({text:m,y:c}),l<_&&(l=_),c+=u,m=v):(_=f,m+=v),p==s-1&&(d.push({text:m,y:c}),m!==v&&l>1;break;case"bottom":g=e.height-e.textHeight}var x=e.background;for(x&&(t.fillStyle=x,t.fillRect(0,0,e.width,e.height)),e.outline?t.strokeStyle=e.color:t.fillStyle=e.color,r=0;r>1;break;case"right":case"end":n=a}r.outline?t.strokeText(e,n,i):t.fillText(e,n,i)},Statics:{measureFontHeight:function(t){var e,i=document.documentElement,r=n.createElement("div",{style:{font:t,position:"absolute"},innerHTML:"M"});return i.appendChild(r),e=r.offsetHeight,i.removeChild(r),e}}});return s}),define(function(t,e,i){var r=t("hilo/core/Class"),n=t("hilo/core/Hilo"),a=t("hilo/view/Container"),o=t("hilo/view/Bitmap"),s=r.create({Extends:a,constructor:function(t){t=t||{},this.id=this.id||t.id||n.getUid("BitmapText"),s.superclass.constructor.call(this,t);var e=t.text+"";e&&(this.text="",this.setText(e)),this.pointerChildren=!1},glyphs:null,letterSpacing:0,text:"",textAlign:"left",setText:function(t){var e=this,i=t.toString(),r=i.length;if(e.text!=i){e.text=i;var n,a,o,s,h=0,l=0,c=0;for(n=0;n0?e.letterSpacing:0),e.children[n]?(s=e.children[n],s.setImage(o.image,o.rect)):(s=e._createBitmap(o),e.addChild(s)),s.x=c,h=c+o.rect[2],l=Math.max(l,o.rect[3]));for(n=e.children.length-1;n>=r;n--)e._releaseBitmap(e.children[n]),e.children[n].removeFromParent();return e.width=h,e.height=l,this.setTextAlign(),e}},_createBitmap:function(t){var e;return s._pool.length?(e=s._pool.pop(),e.setImage(t.image,t.rect)):e=new o({image:t.image,rect:t.rect}),e},_releaseBitmap:function(t){s._pool.push(t)},setTextAlign:function(t){switch(this.textAlign=t||this.textAlign,this.textAlign){case"center":this.pivotX=.5*this.width;break;case"right":this.pivotX=this.width;break;case"left":default:this.pivotX=0}return this},hasGlyphs:function(t){var e=this.glyphs;if(!e)return!1;t=t.toString();var i,r=t.length;for(i=0;i=this._targetFPS?(this._measuredFPS=1e3/(this._tickTime/this._tickCount)+.5>>0,this._tickCount=0,this._tickTime=0):this._tickTime+=t-this._lastTime,this._lastTime=t;for(var r=i.slice(0),n=0,a=r.length;n=0&&e.splice(i,1)},nextTick:function(t){var e=this,i={tick:function(r){e.removeTick(i),t()}};return e.addTick(i),i},timeout:function(t,e){var i=this,r=(new Date).getTime()+e,n={tick:function(){var e=(new Date).getTime(),a=e-r;a>=0&&(i.removeTick(n),t())}};return i.addTick(n),n},interval:function(t,e){var i=this,r=(new Date).getTime()+e,n={tick:function(){var i=(new Date).getTime(),n=i-r;n>=0&&(n=r)return-1;for(e<0&&(e=r+e),i=e;i=1?1:s;var l=r.ease?r.ease(s):s;r.reverse&&r.isStart&&(r._reverseFlag<0&&(s=1-s,l=1-l),s<1e-7&&(r.repeat>0&&r._repeatCount++>=r.repeat||0==r.repeat&&!r.loop?h=!0:(r._startTime=t(),r._pausedTime=0,r._reverseFlag*=-1))),r.isStart||(r.setProps(r._fromProps,r._toProps),r.isStart=!0,r.onStart&&r.onStart.call(r,r)),r.time=a,r._render(l),(o=r.onUpdate)&&o.call(r,s,r),s>=1&&(r.reverse?(r._startTime=t(),r._pausedTime=0,r._reverseFlag*=-1):r.loop||r.repeat>0&&r._repeatCount++0&&u<=e?(c._render(s),c.time=a,n.add(c)):r.isComplete&&(u<0||u>e)&&c.start()}return r.isComplete?((o=r.onComplete)&&o.call(r,r),!0):void 0}}},Statics:{_tweens:[],tick:function(){var e,i,r=n._tweens,a=r.length;for(i=0;i-1&&r.splice(e,1);else for(e=0;e=i)return void t.fire("complete");if(t._currentIndexe.z})},tick:function(){this.sortZ()}});return o}();return a}),define(function(t,e,i){var r=t("hilo/core/Hilo"),n=t("hilo/core/Class"),a=t("hilo/view/View"),o=t("hilo/view/Container"),s=t("hilo/view/Drawable"),h=t("hilo/util/util"),l=function(){function t(t,e){return e?t+2*(Math.random()-.5)*e:t}for(var e=["x","y","vx","vy","ax","ay","rotation","rotationV","scale","scaleV","alpha","alphaV","life"],i=[],l=0,c=e.length;l=this._emitTime&&(this._currentRunTime=0,this._emitTime=t(this.emitTime,this.emitTimeVar),this._emit()),this._totalRunTime>=this.totalTime&&this.stop())},_emit:function(){for(var e=t(this.emitNum,this.emitNumVar)>>0,i=0;i=0;e--)this.children[e].destroy()}}),v=n.create({Extends:a,constructor:function(t){this.id=this.id||t.id||r.getUid("Particle"),v.superclass.constructor.call(this,t),this.init(t)},onUpdate:function(t){if(t*=.001,this._died)return!1;var e=this.ax+this.system.gx,i=this.ay+this.system.gy;return this.vx+=e*t,this.vy+=i*t,this.x+=this.vx*t,this.y+=this.vy*t,this.rotation+=this.rotationV,this._time>.1&&(this.alpha+=this.alphaV),this.scale+=this.scaleV,this.scaleX=this.scaleY=this.scale,this._time+=t,this._time>=this.life||this.alpha<=0?(this.destroy(),!1):void 0},setImage:function(t,e){this.drawable=this.drawable||new s,e=e||[0,0,t.width,t.height],this.width=e[2],this.height=e[3],this.drawable.rect=e,this.drawable.image=t},destroy:function(){this._died=!0,this.alpha=0,this.removeFromParent(),f.push(this)},init:function(e){this.system=e.system,this._died=!1,this._time=0,this.alpha=1;for(var r=0,n=i.length;r>0]),this.setImage(e.image,s),void 0!==e.pivotX&&(this.pivotX=e.pivotX*s[2]),void 0!==e.pivotY&&(this.pivotY=e.pivotY*s[3])}},Statics:{create:function(t){if(f.length>0){var e=f.pop();return e.init(t),e}return new v(t)}}});return p}();return l}); \ No newline at end of file +define(function(t,e,i){var r=function(){var t=navigator.userAgent,e=document,i=window,r=e.documentElement,n={iphone:/iphone/i.test(t),ipad:/ipad/i.test(t),ipod:/ipod/i.test(t),ios:/iphone|ipad|ipod/i.test(t),android:/android/i.test(t),webkit:/webkit/i.test(t),chrome:/chrome/i.test(t),safari:/safari/i.test(t),firefox:/firefox/i.test(t),ie:/msie/i.test(t),opera:/opera/i.test(t),supportTouch:"ontouchstart"in i,supportCanvas:null!=e.createElement("canvas").getContext,supportStorage:!1,supportOrientation:"orientation"in i||"orientation"in i.screen,supportDeviceMotion:"ondevicemotion"in i};try{var a="hilo";localStorage.setItem(a,a),localStorage.removeItem(a),n.supportStorage=!0}catch(o){}var s=n.jsVendor=n.webkit?"webkit":n.firefox?"webkit":n.opera?"o":n.ie?"ms":"",h=n.cssVendor="-"+s+"-",l=e.createElement("div"),c=l.style,u=void 0!=c[s+"Transform"],d=void 0!=c[s+"Perspective"];d&&(l.id="test3d",c=e.createElement("style"),c.textContent="@media ("+h+"transform-3d){#test3d{height:3px}}",e.head.appendChild(c),r.appendChild(l),d=3==l.offsetHeight,e.head.removeChild(c),r.removeChild(l)),n.supportTransform=u,n.supportTransform3D=d;var f=n.supportTouch,p=f?"touchstart":"mousedown",v=f?"touchmove":"mousemove",m=f?"touchend":"mouseup";return n.POINTER_START=p,n.POINTER_MOVE=v,n.POINTER_END=m,n}();return r}),define(function(t,e,i){var r={copy:function(t,e,i){for(var r in e)i&&!t.hasOwnProperty(r)&&void 0===t[r]||(t[r]=e[r]);return t}};return r}),define(function(t,e,i){var r=t("hilo/util/browser"),n=t("hilo/util/util"),a=window,o=document,s=o.documentElement,h=0,l={},c={version:"1.6.0",getUid:function(t){var e=++h;if(t){var i=t.charCodeAt(t.length-1);return i>=48&&i<=57&&(t+="_"),t+e}return e},viewToString:function(t){for(var e,i=t;i;)e=e?i.id+"."+e:i.id,i=i.parent;return e},copy:function(t,e,i){return n.copy(t,e,i),l.copy||(l.copy=!0,console.warn("Hilo.copy has been Deprecated! Use Hilo.util.copy instead.")),t},browser:r,event:{POINTER_START:r.POINTER_START,POINTER_MOVE:r.POINTER_MOVE,POINTER_END:r.POINTER_END},align:{TOP_LEFT:"TL",TOP:"T",TOP_RIGHT:"TR",LEFT:"L",CENTER:"C",RIGHT:"R",BOTTOM_LEFT:"BL",BOTTOM:"B",BOTTOM_RIGHT:"BR"},getElementRect:function(t){var e;try{e=t.getBoundingClientRect()}catch(i){e={top:t.offsetTop,left:t.offsetLeft,right:t.offsetLeft+t.offsetWidth,bottom:t.offsetTop+t.offsetHeight}}var r=(a.pageXOffset||s.scrollLeft)-(s.clientLeft||0)||0,n=(a.pageYOffset||s.scrollTop)-(s.clientTop||0)||0,o=a.getComputedStyle?getComputedStyle(t):t.currentStyle,h=parseInt,l=h(o.paddingLeft)+h(o.borderLeftWidth)||0,c=h(o.paddingTop)+h(o.borderTopWidth)||0,u=h(o.paddingRight)+h(o.borderRightWidth)||0,d=h(o.paddingBottom)+h(o.borderBottomWidth)||0,f=e.top||0,p=e.left||0,v=e.right||0,m=e.bottom||0;return{left:p+r+l,top:f+n+c,width:v-u-p-l,height:m-d-f-c}},createElement:function(t,e){var i,r,n,a=o.createElement(t);for(i in e)if(r=e[i],"style"===i)for(n in r)a.style[n]=r[n];else a[i]=r;return a},getElement:function(t){return o.getElementById(t)},setElementStyleByView:function(t){var e=t.drawable,i=e.domElement.style,r=t._stateCache||(t._stateCache={}),n=c.browser.jsVendor,a="px",o=!1;if(this.cacheStateIfChanged(t,["visible"],r)&&(i.display=t.visible?"":"none"),this.cacheStateIfChanged(t,["alpha"],r)&&(i.opacity=t.alpha),t.visible&&!(t.alpha<=0)){if(this.cacheStateIfChanged(t,["width"],r)&&(i.width=t.width+a),this.cacheStateIfChanged(t,["height"],r)&&(i.height=t.height+a),this.cacheStateIfChanged(t,["depth"],r)&&(i.zIndex=t.depth+1),t.transform){var s=t.transform;(o=this.cacheStateIfChanged(t,["pivotX","pivotY"],r))&&(i[n+"TransformOrigin"]="0 0"),i[n+"Transform"]="matrix3d("+s.a+", "+s.b+", 0, 0, "+s.c+", "+s.d+", 0, 0, 0, 0, 1, 0, "+s.tx+", "+s.ty+", 0, 1)"}else(o=this.cacheStateIfChanged(t,["pivotX","pivotY"],r))&&(i[n+"TransformOrigin"]=t.pivotX+a+" "+t.pivotY+a),(this.cacheStateIfChanged(t,["x","y","rotation","scaleX","scaleY"],r)||o)&&(i[n+"Transform"]=this.getTransformCSS(t));this.cacheStateIfChanged(t,["background"],r)&&(i.backgroundColor=t.background),i.pointerEvents||(i.pointerEvents="none");var h=e.image;if(h){var l=h.src;l!==r.image&&(r.image=l,i.backgroundImage="url("+l+")");var u=e.rect;if(u){var d=u[0],f=u[1];d!==r.sx&&(r.sx=d,i.backgroundPositionX=-d+a),f!==r.sy&&(r.sy=f,i.backgroundPositionY=-f+a)}}var p=t.mask;if(p){var v=p.drawable.domElement.style.backgroundImage;v!==r.maskImage&&(r.maskImage=v,i[n+"MaskImage"]=v,i[n+"MaskRepeat"]="no-repeat");var m=p.x,_=p.y;m===r.maskX&&_===r.maskY||(r.maskX=m,r.maskY=_,i[n+"MaskPosition"]=m+a+" "+_+a)}}},cacheStateIfChanged:function(t,e,i){var r,n,a,o,s=!1;for(r=0,n=e.length;r=6?(e=s[0],i=s[1],r=s[2],n=s[3],a=s[4],o=s[5]):(e=t.a,i=t.b,r=t.c,n=t.d,a=t.tx,o=t.ty),this.a=h*e+l*r,this.b=h*i+l*n,this.c=c*e+u*r,this.d=c*i+u*n,this.tx=d*e+f*r+a,this.ty=d*i+f*n+o,this},rotate:function(t){var e=Math.sin(t),i=Math.cos(t),r=this.a,n=this.b,a=this.c,o=this.d,s=this.tx,h=this.ty;return this.a=r*i-n*e,this.b=r*e+n*i,this.c=a*i-o*e,this.d=a*e+o*i,this.tx=s*i-h*e,this.ty=s*e+h*i,this},scale:function(t,e){return this.a*=t,this.d*=e,this.c*=t,this.b*=e,this.tx*=t,this.ty*=e,this},translate:function(t,e){return this.tx+=t,this.ty+=e,this},identity:function(){return this.a=this.d=1,this.b=this.c=this.tx=this.ty=0,this},invert:function(){var t=this.a,e=this.b,i=this.c,r=this.d,n=this.tx,a=t*r-e*i;return this.a=r/a,this.b=-e/a,this.c=-i/a,this.d=t/a,this.tx=(i*this.ty-r*n)/a,this.ty=-(t*this.ty-e*n)/a,this},transformPoint:function(t,e,i){var r=t.x*this.a+t.y*this.c+this.tx,n=t.x*this.b+t.y*this.d+this.ty;return e&&(r=r+.5>>0,n=n+.5>>0),i?{x:r,y:n}:(t.x=r,t.y=n,t)}});return n}),define(function(t,e,i){var r=t("hilo/core/Class"),n={_listeners:null,on:function(t,e,i){for(var r=this._listeners=this._listeners||{},n=r[t]=r[t]||[],a=0,o=n.length;a-1&&o.splice(c,1)}}return 0==o.length&&delete n[r],!0}return!1}},a=r.create({constructor:function(t,e,i){this.type=t,this.target=e,this.detail=i,this.timeStamp=+new Date},type:null,target:null,detail:null,timeStamp:0,stopImmediatePropagation:function(){this._stopped=!0}}),o=window.Event;if(o){var s=o.prototype,h=s.stopImmediatePropagation;s.stopImmediatePropagation=function(){h&&h.call(this),this._stopped=!0}}return n}),define(function(t,e,i){var r=t("hilo/core/Class"),n=t("hilo/util/util"),a=r.create({constructor:function(t){this.init(t)},image:null,rect:null,init:function(t){var e=this,i=e.image;a.isDrawable(t)?e.image=t:n.copy(e,t,!0);var r=e.image;if("string"==typeof r){if(!i||r!==i.getAttribute("src")){e.image=null;var o=new Image;return t.crossOrigin&&(o.crossOrigin="Anonymous"),o.onload=function(){o.onload=null,e.init(o)},void(o.src=r)}r=e.image=i}r&&!e.rect&&(e.rect=[0,0,r.width,r.height])},Statics:{isDrawable:function(t){if(!t||!t.tagName)return!1;var e=t.tagName.toLowerCase();return"img"===e||"canvas"===e||"video"===e}}});return a}),define(function(t,e,i){var r=t("hilo/core/Class"),n=t("hilo/util/util"),a=r.create({constructor:function(t){t=t||{},n.copy(this,t,!0)},renderType:null,canvas:null,stage:null,blendMode:"source-over",startDraw:function(t){},draw:function(t){},endDraw:function(t){},transform:function(){},hide:function(){},remove:function(t){},clear:function(t,e,i,r){},resize:function(t,e){}});return a}),define(function(t,e,i){var r=t("hilo/core/Class"),n=t("hilo/core/Hilo"),a=t("hilo/renderer/Renderer"),o=r.create({Extends:a,constructor:function(t){o.superclass.constructor.call(this,t),this.context=this.canvas.getContext("2d")},renderType:"canvas",context:null,startDraw:function(t){return!!(t.visible&&t.alpha>0)&&(t===this.stage&&this.context.clearRect(0,0,t.width,t.height),t.blendMode!==this.blendMode&&(this.context.globalCompositeOperation=this.blendMode=t.blendMode),this.context.save(),!0)},draw:function(t){var e=this.context,i=t.width,r=t.height,n=t.background;n&&(e.fillStyle=n,e.fillRect(0,0,i,r));var a=t.drawable,o=a&&a.image;if(o){var s=a.rect,h=s[2],l=s[3],c=s[4],u=s[5];if(!h||!l)return;i||r||(i=t.width=h,r=t.height=l),(c||u)&&e.translate(c-.5*h,u-.5*l),e.drawImage(o,s[0],s[1],h,l,0,0,i,r)}},endDraw:function(t){this.context.restore()},transform:function(t){var e=t.drawable;if(e&&e.domElement)return void n.setElementStyleByView(t);var i=this.context,r=t.scaleX,a=t.scaleY;if(t===this.stage){var o=this.canvas.style,s=t._scaleX,h=t._scaleY,l=!1;(!s&&1!=r||s&&s!=r)&&(t._scaleX=r,o.width=r*t.width+"px",l=!0),(!h&&1!=a||h&&h!=a)&&(t._scaleY=a,o.height=a*t.height+"px",l=!0),l&&t.updateViewport()}else{var c=t.x,u=t.y,d=t.pivotX,f=t.pivotY,p=t.rotation%360,v=t.transform,m=t.mask;m&&(m._render(this),i.clip());var _=t.align;if(_){var g=t.getAlignPosition();c=g.x,u=g.y}v?i.transform(v.a,v.b,v.c,v.d,v.tx,v.ty):(0==c&&0==u||i.translate(c,u),0!=p&&i.rotate(p*Math.PI/180),1==r&&1==a||i.scale(r,a),0==d&&0==f||i.translate(-d,-f))}t.alpha>0&&(i.globalAlpha*=t.alpha)},remove:function(t){var e=t.drawable,i=e&&e.domElement;if(i){var r=i.parentNode;r&&r.removeChild(i)}},clear:function(t,e,i,r){this.context.clearRect(t,e,i,r)},resize:function(t,e){var i=this.canvas,r=this.stage,n=i.style;i.width=t,i.height=e,n.width=r.width*r.scaleX+"px",n.height=r.height*r.scaleY+"px"}});return o}),define(function(t,e,i){var r=t("hilo/core/Class"),n=t("hilo/core/Hilo"),a=t("hilo/renderer/Renderer"),o=t("hilo/view/Drawable"),s=function(){function t(t,e){var i=t.tagName||"div",r=e.image,a=t.width||r&&r.width,o=t.height||r&&r.height,s=n.createElement(i),h=s.style;if(t.id&&(s.id=t.id),h.position="absolute",h.left=(t.left||0)+"px",h.top=(t.top||0)+"px",h.width=a+"px",h.height=o+"px","canvas"==i){if(s.width=a,s.height=o,r){var l=s.getContext("2d"),c=e.rect||[0,0,a,o];l.drawImage(r,c[0],c[1],c[2],c[3],t.x||0,t.y||0,t.width||c[2],t.height||c[3])}}else if(h.opacity=void 0!=t.alpha?t.alpha:1,(t===this.stage||t.clipChildren)&&(h.overflow="hidden"),r&&r.src){h.backgroundImage="url("+r.src+")";var u=t.rectX||0,d=t.rectY||0;h.backgroundPosition=-u+"px "+-d+"px"}return s}return r.create({Extends:a,constructor:function(t){s.superclass.constructor.call(this,t)},renderType:"dom",startDraw:function(e){var i=e.drawable=e.drawable||new o;return i.domElement=i.domElement||t(e,i),!0},draw:function(t){var e=t.parent,i=t.drawable.domElement,r=i.parentNode;if(e){var n=e.drawable.domElement;if(n!=r&&n.appendChild(i),!t.width&&!t.height){var a=t.drawable.rect;a&&(a[2]||a[3])&&(t.width=a[2],t.height=a[3])}}else t!==this.stage||r||(i.style.overflow="hidden",this.canvas.appendChild(i))},transform:function(t){if(n.setElementStyleByView(t),t===this.stage){var e=this.canvas.style,i=t._scaleX,r=t._scaleY,a=t.scaleX,o=t.scaleY;(!i&&1!=a||i&&i!=a)&&(t._scaleX=a,e.width=a*t.width+"px"),(!r&&1!=o||r&&r!=o)&&(t._scaleY=o,e.height=o*t.height+"px")}},remove:function(t){var e=t.drawable,i=e&&e.domElement;if(i){var r=i.parentNode;r&&r.removeChild(i)}},hide:function(t){var e=t.drawable&&t.drawable.domElement;e&&(e.style.display="none")},resize:function(t,e){var i=this.canvas.style;i.width=t+"px",i.height=e+"px","absolute"!=i.position&&(i.position="relative")}})}();return s}),define(function(t,e,i){var r=t("hilo/core/Class"),n=t("hilo/core/Hilo"),a=t("hilo/renderer/Renderer"),o=t("hilo/geom/Matrix"),s=Math.PI/180,h=r.create({Extends:a,Statics:{MAX_BATCH_NUM:2e3,ATTRIBUTE_NUM:5,isSupport:function(){if(void 0==this._isSupported){var t=document.createElement("canvas");t.getContext&&(t.getContext("webgl")||t.getContext("experimental-webgl"))?this._isSupported=!0:this._isSupported=!1}return this._isSupported},contextOptions:null},renderType:"webgl",gl:null,_isContextLost:!1,_cacheTexture:{},constructor:function(t){h.superclass.constructor.call(this,t);var e=this,i=h.contextOptions||{};this.gl=this.canvas.getContext("webgl",i)||this.canvas.getContext("experimental-webgl",i),this.maxBatchNum=h.MAX_BATCH_NUM,this.positionStride=4*h.ATTRIBUTE_NUM;var r=this.maxBatchNum*h.ATTRIBUTE_NUM*4,n=6*this.maxBatchNum;this.arrayBuffer=new ArrayBuffer(4*r),this.float32Array=new Float32Array(this.arrayBuffer),this.uint32Array=new Uint32Array(this.arrayBuffer),this.indexs=new Uint16Array(n);for(var a=0,o=0;a0)&&(t===this.stage&&this.clear(),!0)},draw:function(t){var e=t.width,i=t.height,r=(t.background,t.drawable),n=r&&r.image;if(n){var a=r.rect,o=a[2],s=a[3];e||i||(e=t.width=o,i=t.height=s),this.batchIndex>=this.maxBatchNum&&this._renderBatches();var h=this._createVertexs(n,a[0],a[1],o,s,0,0,e,i),l=this.batchIndex*this.positionStride,c=this.float32Array,u=this.uint32Array,d=(t.tint>>16)+(65280&t.tint)+((255&t.tint)<<16)+(255*t.__webglRenderAlpha<<24);c[l+0]=h[0],c[l+1]=h[1],c[l+2]=h[2],c[l+3]=h[3],u[l+4]=d,c[l+5]=h[4],c[l+6]=h[5],c[l+7]=h[6],c[l+8]=h[7],u[l+9]=d,c[l+10]=h[8],c[l+11]=h[9],c[l+12]=h[10],c[l+13]=h[11],u[l+14]=d,c[l+15]=h[12],c[l+16]=h[13],c[l+17]=h[14],c[l+18]=h[15],u[l+19]=d;for(var f=t.__webglWorldMatrix,p=0;p<4;p++){var v=c[l+5*p],m=c[l+5*p+1];c[l+5*p]=f.a*v+f.c*m+f.tx,c[l+5*p+1]=f.b*v+f.d*m+f.ty}t.__textureImage=n,this.sprites[this.batchIndex++]=t}},endDraw:function(t){t===this.stage&&this._renderBatches()},transform:function(t){var e=t.drawable;if(e&&e.domElement)return void n.setElementStyleByView(t);var i=t.scaleX,r=t.scaleY;if(t===this.stage){var a=this.canvas.style,s=t._scaleX,h=t._scaleY,l=!1;(!s&&1!=i||s&&s!=i)&&(t._scaleX=i,a.width=i*t.width+"px",l=!0),(!h&&1!=r||h&&h!=r)&&(t._scaleY=r,a.height=r*t.height+"px",l=!0),l&&t.updateViewport(),t.__webglWorldMatrix=t.__webglWorldMatrix||new o(1,0,0,1,0,0)}else t.parent&&(t.__webglWorldMatrix=t.__webglWorldMatrix||new o(1,0,0,1,0,0),this._setConcatenatedMatrix(t,t.parent));t.alpha>0&&(t.parent&&t.parent.__webglRenderAlpha?t.__webglRenderAlpha=t.alpha*t.parent.__webglRenderAlpha:t.__webglRenderAlpha=t.alpha)},remove:function(t){var e=t.drawable,i=e&&e.domElement;if(i){var r=i.parentNode;r&&r.removeChild(i)}},clear:function(t,e,i,r){this.gl.clear(this.gl.COLOR_BUFFER_BIT)},resize:function(t,e){if(this.width!==t||this.height!==e){var i=this.canvas,r=this.stage,n=i.style;this.width=i.width=t,this.height=i.height=e,n.width=r.width*r.scaleX+"px",n.height=r.height*r.scaleY+"px",this.gl.viewport(0,0,t,e),this.canvasHalfWidth=.5*t,this.canvasHalfHeight=.5*e,this._uploadProjectionTransform(!0)}},_renderBatches:function(){var t=this.gl;t.bufferSubData(t.ARRAY_BUFFER,0,this.uint32Array.subarray(0,this.batchIndex*this.positionStride));for(var e=0,i=0,r=null,n=0;n0&&(i.bindTexture(i.TEXTURE_2D,this._getTexture(this.sprites[t])),i.drawElements(i.TRIANGLES,6*r,i.UNSIGNED_SHORT,6*t*2))},_uploadProjectionTransform:function(t){this._projectionTransformElements&&!t||(this._projectionTransformElements=new Float32Array([1/this.canvasHalfWidth,0,0,0,-1/this.canvasHalfHeight,0,-1,1,1])),this.gl.uniformMatrix3fv(this.u_projectionTransform,!1,this._projectionTransformElements)},_initShaders:function(){var t=" attribute vec2 a_position;\n attribute vec2 a_TexCoord;\n attribute vec4 a_tint;\n uniform mat3 u_projectionTransform;\n varying vec2 v_TexCoord;\n varying vec4 v_tint;\n void main(){\n gl_Position = vec4((u_projectionTransform * vec3(a_position, 1.0)).xy, 1.0, 1.0);\n v_TexCoord = a_TexCoord;\n v_tint = vec4(a_tint.rgb * a_tint.a, a_tint.a);\n }\n ",e="\n precision mediump float;\n uniform sampler2D u_Sampler;\n varying vec2 v_TexCoord;\n varying vec4 v_tint;\n void main(){\n gl_FragColor = texture2D(u_Sampler, v_TexCoord) * v_tint;\n }\n ";this.defaultShader=new l(this,{v:t,f:e},{attributes:["a_position","a_TexCoord","a_tint"],uniforms:["u_projectionTransform","u_Sampler"]})},_createVertexs:function(t,e,i,r,n,a,o,s,h){var l=this.__tempVertexs||[],c=t.width,u=t.height;r/=c,n/=u,e/=c,i/=u,s=s,h=h,a=a,o=o,r+e>1&&(r=1-e),n+i>1&&(n=1-i);var d=0;return l[d++]=a,l[d++]=o,l[d++]=e,l[d++]=i,l[d++]=a+s,l[d++]=o,l[d++]=e+r,l[d++]=i,l[d++]=a,l[d++]=o+h,l[d++]=e,l[d++]=i+n,l[d++]=a+s,l[d++]=o+h,l[d++]=e+r,l[d++]=i+n,l},_setConcatenatedMatrix:function(t,e){var i=t.__webglWorldMatrix,r=1,n=0,a=t.rotation%360,o=t.pivotX,h=t.pivotY,l=t.scaleX,c=t.scaleY,u=t.transform;if(u)i.copy(u);else{if(a){var d=a*s;r=Math.cos(d),n=Math.sin(d)}var f=t.getAlignPosition();i.a=r*l,i.b=n*l,i.c=-n*c,i.d=r*c,i.tx=f.x-i.a*o-i.c*h,i.ty=f.y-i.b*o-i.d*h}i.concat(e.__webglWorldMatrix)},_getTexture:function(t){var e=t.__textureImage,i=this._cacheTexture[e.src];return i||(i=this.activeShader.uploadTexture(e)),i}}),l=function(t,e,i){this.renderer=t,this.gl=t.gl,this.program=this._createProgram(this.gl,e.v,e.f),i=i||{},this.attributes=i.attributes||[],this.uniforms=i.uniforms||[]};return l.prototype={active:function(){var t=this,e=t.renderer,i=t.gl,r=t.program;r&&i&&(e.activeShader=t,i.useProgram(r),t.attributes.forEach(function(t){e[t]=i.getAttribLocation(r,t),i.enableVertexAttribArray(e[t])}),t.uniforms.forEach(function(t){e[t]=i.getUniformLocation(r,t)}),t.width===e.width&&t.height===e.height||(t.width=e.width,t.height=e.height,e._uploadProjectionTransform()))},uploadTexture:function(t){var e=this.gl,i=this.renderer,r=e.createTexture(),n=i.u_Sampler;return e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,r),e.pixelStorei(e.UNPACK_PREMULTIPLY_ALPHA_WEBGL,1),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,t),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.uniform1i(n,0),e.bindTexture(e.TEXTURE_2D,null),this.renderer._cacheTexture[t.src]=r,r},_createProgram:function(t,e,i){var r=this._createShader(t,t.VERTEX_SHADER,e),n=this._createShader(t,t.FRAGMENT_SHADER,i);if(!r||!n)return null;var a=t.createProgram();if(a){t.attachShader(a,r),t.attachShader(a,n),t.linkProgram(a),t.deleteShader(n),t.deleteShader(r);var o=t.getProgramParameter(a,t.LINK_STATUS);if(!o){var s=t.getProgramInfoLog(a);return console.log("Failed to link program: "+s),t.deleteProgram(a),null}}return a},_createShader:function(t,e,i){var r=t.createShader(e);if(r){t.shaderSource(r,i),t.compileShader(r);var n=t.getShaderParameter(r,t.COMPILE_STATUS);if(!n){var a=t.getShaderInfoLog(r);return console.log("Failed to compile shader: "+a),t.deleteShader(r),null}}return r}},h}),define(function(t,e,i){var r=t("hilo/core/Hilo"),n=t("hilo/core/Class"),a=t("hilo/event/EventMixin"),o=t("hilo/geom/Matrix"),s=t("hilo/util/util"),h=function(){function t(t,e,i){for(var r,n,a,o,s=0,h=!1,l=0,c=i.length;ld.x?(r=d.x,n=u.x):(r=u.x,n=d.x),t>=r&&t<=n))h=!0;else if(u.y>d.y?(a=d.y,o=u.y):(a=u.y,o=d.y),!(eo)){var f=(e-u.y)*(d.x-u.x)/(d.y-u.y)+u.x;if(f>t?s++:f==t&&(h=!0),u.x>t&&u.y==e){var p=i[(c+l-1)%c];(p.ye||p.y>e&&d.ys?s=c:cl?l=c:c=0)return!1;u>i.overlap&&(i.overlap=u,i.normal.x=p.x,i.normal.y=p.y)}return i}return n.create({Mixes:a,constructor:function(t){t=t||{},this.id=this.id||t.id||r.getUid("View"),s.copy(this,t,!0)},tint:16777215,id:null,x:0,y:0,width:0,height:0,alpha:1,rotation:0,visible:!0,pivotX:0,pivotY:0,scaleX:1,scaleY:1,pointerEnabled:!0,background:null,mask:null,align:null,drawable:null,boundsArea:null,parent:null,depth:-1,transform:null,blendMode:"source-over",getStage:function(){for(var t,e=this;t=e.parent;)e=t;return e.canvas?e:null},getScaledWidth:function(){return this.width*this.scaleX},getScaledHeight:function(){return this.height*this.scaleY},addTo:function(t,e){return"number"==typeof e?t.addChildAt(this,e):t.addChild(this),this},removeFromParent:function(){var t=this.parent;return t&&t.removeChild(this),this},getBounds:function(){for(var t,e,i,r,n,a,o,s=this.width,h=this.height,l=this.getConcatenatedMatrix(),c=this.boundsArea||[{x:0,y:0},{x:s,y:0},{x:s,y:h},{x:0,y:h}],u=[],d=0,f=c.length;de?r=e:ni?a=i:o>1,r=0;break;case"TR":i=o-n,r=0;break;case"L":i=0,r=s-a>>1;break;case"C":i=o-n>>1,r=s-a>>1;break;case"R":i=o-n,r=s-a>>1;break;case"BL":i=0,r=s-a;break;case"B":i=o-n>>1,r=s-a;break;case"BR":i=o-n,r=s-a}}return{x:i,y:r}},hitTestPoint:function(e,i,r){var n=this.getBounds(),a=e>=n.x&&e<=n.x+n.width&&i>=n.y&&i<=n.y+n.height;return a&&r&&(a=t(e,i,n)),a},hitTestObject:function(t,i){var r=this.getBounds(),n=t.getBounds(),a=r.x<=n.x+n.width&&n.x<=r.x+r.width&&r.y<=n.y+n.height&&n.y<=r.y+r.height;return a&&i&&(a=e(r,n)),!!a},_render:function(t,e){this.onUpdate&&this.onUpdate(e)===!1||!t.startDraw(this)||(t.transform(this),this.render(t,e),t.endDraw(this))},_fireMouseEvent:function(t){if(t.eventCurrentTarget=this,this.fire(t),"mousemove"==t.type){if(!this.__mouseOver){this.__mouseOver=!0;var e=s.copy({},t);e.type="mouseover",this.fire(e)}}else"mouseout"==t.type&&(this.__mouseOver=!1);var i=this.parent;t._stopped||t._stopPropagationed||!i||("mouseout"==t.type||"touchout"==t.type?i.hitTestPoint(t.stageX,t.stageY,!0)||i._fireMouseEvent(t):i._fireMouseEvent(t))},onUpdate:null,render:function(t,e){t.draw(this)},toString:function(){return r.viewToString(this)}})}();return h}),define(function(t,e,i){var r,n,a=t("hilo/view/Drawable"),o=t("hilo/util/browser"),s={_cacheDirty:!0,cache:function(t){(t||this._cacheDirty||!this.drawable)&&this.updateCache()},updateCache:function(){o.supportCanvas&&(r||(r=document.createElement("canvas"),n=r.getContext("2d")),r.width=this.width,r.height=this.height,this._draw(n),this.drawable=this.drawable||new a,this.drawable.init({image:r.toDataURL()}),this._cacheDirty=!1)},setCacheDirty:function(t){this._cacheDirty=t}};return s}),define(function(t,e,i){var r=t("hilo/core/Hilo"),n=t("hilo/core/Class"),a=t("hilo/view/View"),o=n.create({Extends:a,constructor:function(t){t=t||{},this.id=this.id||t.id||r.getUid("Container"),o.superclass.constructor.call(this,t),this.children?this._updateChildren():this.children=[]},children:null,pointerChildren:!0,clipChildren:!1,getNumChildren:function(){return this.children.length},addChildAt:function(t,e){var i=this.children,r=i.length,n=t.parent;e=e<0?0:e>r?r:e;var a=this.getChildIndex(t);if(a==e)return this;if(a>=0?(i.splice(a,1),e=e==r?r-1:e):n&&n.removeChild(t),i.splice(e,0,t),a<0)this._updateChildren(e);else{var o=a=e.length)return null;var i=e[t];if(i){if(!i.__renderer)for(var r=i;r=r.parent;){if(r.renderer){i.__renderer=r.renderer;break}if(r.__renderer){i.__renderer=r.__renderer;break}}i.__renderer&&i.__renderer.remove(i),i.parent=null,i.depth=-1}return e.splice(t,1),this._updateChildren(t),i},removeChild:function(t){return this.removeChildAt(this.getChildIndex(t))},removeChildById:function(t){for(var e,i=this.children,r=0,n=i.length;r=e.length?null:e[t]},getChildById:function(t){for(var e,i=this.children,r=0,n=i.length;r=0&&r!=e){var n=i.length;e=e<0?0:e>=n?n-1:e,i.splice(r,1),i.splice(e,0,t),this._updateChildren()}return this},swapChildren:function(t,e){var i=this.children,r=this.getChildIndex(t),n=this.getChildIndex(e);t.depth=n,i[n]=t,e.depth=r,i[r]=e},swapChildrenAt:function(t,e){var i=this.children,r=this.getChildAt(t),n=this.getChildAt(e);r.depth=e,i[e]=r,n.depth=t,i[t]=n},sortChildren:function(t){var e=t,i=this.children;if("string"==typeof e){var r=e;e=function(t,e){return e[r]-t[r]}}i.sort(e),this._updateChildren()},_updateChildren:function(t,e){var i,r=this.children;t=t||0,e=e||r.length;for(var n=t;n=0;l--)if(a=h[l],!(!a||!a.visible||a.alpha<=0||n&&!a.pointerEnabled))if(a.children&&a.children.length&&(!n||a.pointerChildren)&&(o=a.getViewAtPoint(t,e,i,r,n)),o){if(!r)return o;o.length&&(s=s.concat(o))}else if(a.hitTestPoint(t,e,i)){if(!r)return a;s.push(a)}return r&&s.length?s:null},render:function(t,e){o.superclass.render.call(this,t,e);var i,r,n,a=this.children.slice(0);for(i=0,r=a.length;ir?r:e,i[e]=t,t.name&&(this._frameNames[t.name]=t),(0!=e||this.width)&&this.height||(this.width=t.rect[2],this.height=t.rect[3]),this},getFrame:function(t){if("number"==typeof t){var e=this._frames;return t<0||t>=e.length?null:e[t]}return this._frameNames[t]},getFrameIndex:function(t){var e=this._frames,i=e.length,r=-1;if("number"==typeof t)r=t;else{var n="string"==typeof t?this._frameNames[t]:t;if(n)for(var a=0;a=i?i-1:r,this.paused=e,this._firstRender=!0,this},_render:function(t,e){var i,r=this.currentFrame;if(this._firstRender?(i=r,this._firstRender=!1):i=this._nextFrame(e),i!=r){this.currentFrame=i;var n=this._frames[i].callback;n&&n.call(this)}this.onEnterFrame&&this.onEnterFrame(i),this.drawable.init(this._frames[i]),s.superclass._render.call(this,t,e)},_nextFrame:function(t){var e=this._frames,i=e.length,r=this.currentFrame,n=e[r],a=n.duration||this.interval,o=this._frameElapsed,s=0!=r||this.drawable?o+(this.timeBased?t:1):0;return o=this._frameElapsed=s=i-1)&&this.stop(),this.paused||0!=o||(null!=n.next?r=this.getFrameIndex(n.next):r>=i-1?r=0:this.drawable&&r++),r},setFrameCallback:function(t,e){return t=this.getFrame(t),t&&(t.callback=e),this},onEnterFrame:null});return s}),define(function(t,e,i){var r=t("hilo/core/Hilo"),n=t("hilo/core/Class"),a=t("hilo/view/View"),o=t("hilo/view/Drawable"),s=n.create({Extends:a,constructor:function(t){t=t||{},this.id=this.id||t.id||r.getUid("DOMElement"),s.superclass.constructor.call(this,t),this.drawable=new o;var e=this.drawable.domElement=t.element||r.createElement("div");e.id=this.id,this.pointerEnabled&&!e.style.pointerEvents&&(e.style.pointerEvents="visible")},_render:function(t,e){this.onUpdate&&this.onUpdate(e)===!1||(t.transform(this),this.visible&&this.alpha>0&&this.render(t,e))},render:function(t,e){if("dom"!==t.renderType){var i=t.canvas,n=this.parent,a=t._domElementContainer;t._domElementContainer||(a=t._domElementContainer=r.createElement("div",{style:{position:"absolute",transform:"scale3d("+n.scaleX+","+n.scaleY+", 1)",transformOrigin:"0 0",zIndex:"1"}}),i.parentNode.insertBefore(t._domElementContainer,i.nextSibling));var o,s=this.drawable.domElement,h=this.depth,l=a.childNodes[0];if(s.parentNode)return;for(;l&&3!=l.nodeType&&(o=parseInt(l.style.zIndex)||0,!(o<=0||o>h));)l=l.nextSibling;a.insertBefore(this.drawable.domElement,l)}else t.draw(this)}});return s}),define(function(t,e,i){var r=t("hilo/core/Hilo"),n=t("hilo/core/Class"),a=t("hilo/view/View"),o=t("hilo/view/CacheMixin"),s=function(){var t=document.createElement("canvas"),e=t.getContext&&t.getContext("2d");return n.create({Extends:a,Mixes:o,constructor:function(t){t=t||{},this.id=this.id||t.id||r.getUid("Graphics"),s.superclass.constructor.call(this,t),this._actions=[]},lineWidth:1,lineAlpha:1,lineCap:null,lineJoin:null,miterLimit:10,hasStroke:!1,strokeStyle:"0",hasFill:!1,fillStyle:"0",fillAlpha:0,lineStyle:function(t,e,i,r,n,a){var o=this,s=o._addAction;return s.call(o,["lineWidth",o.lineWidth=t||1]),s.call(o,["strokeStyle",o.strokeStyle=e||"0"]),s.call(o,["lineAlpha",o.lineAlpha=i||1]),void 0!=r&&s.call(o,["lineCap",o.lineCap=r]),void 0!=n&&s.call(o,["lineJoin",o.lineJoin=n]),void 0!=a&&s.call(o,["miterLimit",o.miterLimit=a]),o.hasStroke=!0,o},setLineDash:function(t){return this._addAction(["setLineDash",t])},beginFill:function(t,e){var i=this,r=i._addAction;return r.call(i,["fillStyle",i.fillStyle=t]),r.call(i,["fillAlpha",i.fillAlpha=e||1]),i.hasFill=!0,i},endFill:function(){var t=this,e=t._addAction;return t.hasStroke&&e.call(t,["stroke"]),t.hasFill&&e.call(t,["fill"]),t.setCacheDirty(!0),t},beginLinearGradientFill:function(t,i,r,n,a,o){for(var s=this,h=e.createLinearGradient(t,i,r,n),l=0,c=a.length;l1?a.slice(1):null;"function"==typeof t[o]?t[o].apply(t,s):t[o]=a[1]}},render:function(t,e){var i=this;"canvas"===t.renderType?i._draw(t.context):(i.cache(),t.draw(i))},clear:function(){var t=this;return t._actions.length=0,t.lineWidth=1,t.lineAlpha=1,t.lineCap=null,t.lineJoin=null,t.miterLimit=10,t.hasStroke=!1,t.strokeStyle="0",t.hasFill=!1,t.fillStyle="0",t.fillAlpha=1,t.setCacheDirty(!0),t},_addAction:function(t){var e=this;return e._actions.push(t),e}})}();return s}),define(function(t,e,i){var r=t("hilo/core/Class"),n=t("hilo/core/Hilo"),a=t("hilo/view/View"),o=t("hilo/view/CacheMixin"),s=r.create({Extends:a,Mixes:o,constructor:function(t){t=t||{},this.id=this.id||t.id||n.getUid("Text"),s.superclass.constructor.call(this,t),t.font||(this.font="12px arial"),this._fontHeight=s.measureFontHeight(this.font)},text:"",color:"#000",textAlign:null,textVAlign:null,outline:!1,lineSpacing:0,maxWidth:200,font:null,textWidth:0,textHeight:0,setFont:function(t){var e=this;return e.font!==t&&(e.font=t,e._fontHeight=s.measureFontHeight(t)),e},render:function(t,e){var i=this;if("canvas"===t.renderType)this.drawable?t.draw(i):i._draw(t.context);else if("dom"===t.renderType){var r=i.drawable,n=r.domElement,a=n.style;a.font=i.font,a.textAlign=i.textAlign,a.color=i.color,a.width=i.width+"px",a.height=i.height+"px",a.lineHeight=i._fontHeight+i.lineSpacing+"px",n.innerHTML=i.text,t.draw(this)}else i.cache(),t.draw(i)},_draw:function(t){var e=this,i=e.text.toString();if(i){t.font=e.font,t.textAlign=e.textAlign,t.textBaseline="top";var r,n,a,o,s,h=i.split(/\r\n|\r|\n|/),l=0,c=0,u=e._fontHeight+e.lineSpacing,d=[];for(r=0,o=h.length;re.maxWidth?(d.push({text:m,y:c}),l<_&&(l=_),c+=u,m=v):(_=f,m+=v),p==s-1&&(d.push({text:m,y:c}),m!==v&&l>1;break;case"bottom":g=e.height-e.textHeight}var x=e.background;for(x&&(t.fillStyle=x,t.fillRect(0,0,e.width,e.height)),e.outline?t.strokeStyle=e.color:t.fillStyle=e.color,r=0;r>1;break;case"right":case"end":n=a}r.outline?t.strokeText(e,n,i):t.fillText(e,n,i)},Statics:{measureFontHeight:function(t){var e,i=document.documentElement,r=n.createElement("div",{style:{font:t,position:"absolute"},innerHTML:"M"});return i.appendChild(r),e=r.offsetHeight,i.removeChild(r),e}}});return s}),define(function(t,e,i){var r=t("hilo/core/Class"),n=t("hilo/core/Hilo"),a=t("hilo/view/Container"),o=t("hilo/view/Bitmap"),s=r.create({Extends:a,constructor:function(t){t=t||{},this.id=this.id||t.id||n.getUid("BitmapText"),s.superclass.constructor.call(this,t);var e=t.text+"";e&&(this.text="",this.setText(e)),this.pointerChildren=!1},glyphs:null,letterSpacing:0,text:"",textAlign:"left",setText:function(t){var e=this,i=t.toString(),r=i.length;if(e.text!=i){e.text=i;var n,a,o,s,h=0,l=0,c=0;for(n=0;n0?e.letterSpacing:0),e.children[n]?(s=e.children[n],s.setImage(o.image,o.rect)):(s=e._createBitmap(o),e.addChild(s)),s.x=c,h=c+o.rect[2],l=Math.max(l,o.rect[3]));for(n=e.children.length-1;n>=r;n--)e._releaseBitmap(e.children[n]),e.children[n].removeFromParent();return e.width=h,e.height=l,this.setTextAlign(),e}},_createBitmap:function(t){var e;return s._pool.length?(e=s._pool.pop(),e.setImage(t.image,t.rect)):e=new o({image:t.image,rect:t.rect}),e},_releaseBitmap:function(t){s._pool.push(t)},setTextAlign:function(t){switch(this.textAlign=t||this.textAlign,this.textAlign){case"center":this.pivotX=.5*this.width;break;case"right":this.pivotX=this.width;break;case"left":default:this.pivotX=0}return this},hasGlyphs:function(t){var e=this.glyphs;if(!e)return!1;t=t.toString();var i,r=t.length;for(i=0;i=this._targetFPS?(this._measuredFPS=1e3/(this._tickTime/this._tickCount)+.5>>0,this._tickCount=0,this._tickTime=0):this._tickTime+=t-this._lastTime,this._lastTime=t;for(var r=i.slice(0),n=0,a=r.length;n=0&&e.splice(i,1)},nextTick:function(t){var e=this,i={tick:function(r){e.removeTick(i),t()}};return e.addTick(i),i},timeout:function(t,e){var i=this,r=(new Date).getTime()+e,n={tick:function(){var e=(new Date).getTime(),a=e-r;a>=0&&(i.removeTick(n),t())}};return i.addTick(n),n},interval:function(t,e){var i=this,r=(new Date).getTime()+e,n={tick:function(){var i=(new Date).getTime(),n=i-r;n>=0&&(n=r)return-1;for(e<0&&(e=r+e),i=e;i=1?1:s;var l=r.ease?r.ease(s):s;r.reverse&&r.isStart&&(r._reverseFlag<0&&(s=1-s,l=1-l),s<1e-7&&(r.repeat>0&&r._repeatCount++>=r.repeat||0==r.repeat&&!r.loop?h=!0:(r._startTime=t(),r._pausedTime=0,r._reverseFlag*=-1))),r.isStart||(r.setProps(r._fromProps,r._toProps),r.isStart=!0,r.onStart&&r.onStart.call(r,r)),r.time=a,r._render(l),(o=r.onUpdate)&&o.call(r,s,r),s>=1&&(r.reverse?(r._startTime=t(),r._pausedTime=0,r._reverseFlag*=-1):r.loop||r.repeat>0&&r._repeatCount++0&&u<=e?(c._render(s),c.time=a,n.add(c)):r.isComplete&&(u<0||u>e)&&c.start()}return r.isComplete?((o=r.onComplete)&&o.call(r,r),!0):void 0}}},Statics:{_tweens:[],tick:function(){var e,i,r=n._tweens,a=r.length;for(i=0;i-1&&r.splice(e,1);else for(e=0;e=i)return void t.fire("complete");if(t._currentIndexe.z})},tick:function(){this.sortZ()}});return o}();return a}),define(function(t,e,i){var r=t("hilo/core/Hilo"),n=t("hilo/core/Class"),a=t("hilo/view/View"),o=t("hilo/view/Container"),s=t("hilo/view/Drawable"),h=t("hilo/util/util"),l=function(){function t(t,e){return e?t+2*(Math.random()-.5)*e:t}for(var e=["x","y","vx","vy","ax","ay","rotation","rotationV","scale","scaleV","alpha","alphaV","life"],i=[],l=0,c=e.length;l=this._emitTime&&(this._currentRunTime=0,this._emitTime=t(this.emitTime,this.emitTimeVar),this._emit()),this._totalRunTime>=this.totalTime&&this.stop())},_emit:function(){for(var e=t(this.emitNum,this.emitNumVar)>>0,i=0;i=0;e--)this.children[e].destroy()}}),v=n.create({Extends:a,constructor:function(t){this.id=this.id||t.id||r.getUid("Particle"),v.superclass.constructor.call(this,t),this.init(t)},onUpdate:function(t){if(t*=.001,this._died)return!1;var e=this.ax+this.system.gx,i=this.ay+this.system.gy;return this.vx+=e*t,this.vy+=i*t,this.x+=this.vx*t,this.y+=this.vy*t,this.rotation+=this.rotationV,this._time>.1&&(this.alpha+=this.alphaV),this.scale+=this.scaleV,this.scaleX=this.scaleY=this.scale,this._time+=t,this._time>=this.life||this.alpha<=0?(this.destroy(),!1):void 0},setImage:function(t,e){this.drawable=this.drawable||new s,e=e||[0,0,t.width,t.height],this.width=e[2],this.height=e[3],this.drawable.rect=e,this.drawable.image=t},destroy:function(){this._died=!0,this.alpha=0,this.removeFromParent(),f.push(this)},init:function(e){this.system=e.system,this._died=!1,this._time=0,this.alpha=1;for(var r=0,n=i.length;r>0]),this.setImage(e.image,s),void 0!==e.pivotX&&(this.pivotX=e.pivotX*s[2]),void 0!==e.pivotY&&(this.pivotY=e.pivotY*s[3])}},Statics:{create:function(t){if(f.length>0){var e=f.pop();return e.init(t),e}return new v(t)}}});return p}();return l}); \ No newline at end of file diff --git a/build/cmd/hilo-cmd.zip b/build/cmd/hilo-cmd.zip index 91e468c6..524e0c26 100644 Binary files a/build/cmd/hilo-cmd.zip and b/build/cmd/hilo-cmd.zip differ diff --git a/build/cmd/hilo/core/Class.js b/build/cmd/hilo/core/Class.js index fb4ed9d6..6397ae7e 100644 --- a/build/cmd/hilo/core/Class.js +++ b/build/cmd/hilo/core/Class.js @@ -1,5 +1,5 @@ /** - * Hilo 1.5.0 for cmd + * Hilo 1.6.0 for cmd * Copyright 2016 alibaba.com * Licensed under the MIT License */ diff --git a/build/cmd/hilo/core/Class.min.js b/build/cmd/hilo/core/Class.min.js index 5ae47d52..b1f32a1f 100644 --- a/build/cmd/hilo/core/Class.min.js +++ b/build/cmd/hilo/core/Class.min.js @@ -1,5 +1,5 @@ /** - * Hilo 1.5.0 for cmd + * Hilo 1.6.0 for cmd * Copyright 2016 alibaba.com * Licensed under the MIT License */ diff --git a/build/cmd/hilo/core/Hilo.js b/build/cmd/hilo/core/Hilo.js index f8d77bd2..4cc08f7f 100644 --- a/build/cmd/hilo/core/Hilo.js +++ b/build/cmd/hilo/core/Hilo.js @@ -1,5 +1,5 @@ /** - * Hilo 1.5.0 for cmd + * Hilo 1.6.0 for cmd * Copyright 2016 alibaba.com * Licensed under the MIT License */ @@ -30,7 +30,7 @@ var Hilo = { * Hilo version * @type String */ - version: '1.5.0', + version: '1.6.0', /** * @language=en * Gets a globally unique id. Such as Stage1, Bitmap2 etc. diff --git a/build/cmd/hilo/core/Hilo.min.js b/build/cmd/hilo/core/Hilo.min.js index d48de1fd..599c8c28 100644 --- a/build/cmd/hilo/core/Hilo.min.js +++ b/build/cmd/hilo/core/Hilo.min.js @@ -1,6 +1,6 @@ /** - * Hilo 1.5.0 for cmd + * Hilo 1.6.0 for cmd * Copyright 2016 alibaba.com * Licensed under the MIT License */ -define(function(t,e,a){var r=t("hilo/util/browser"),o=t("hilo/util/util"),n=window,i=document,s=i.documentElement,c=0,h={},f={version:"1.5.0",getUid:function(t){var e=++c;if(t){var a=t.charCodeAt(t.length-1);return a>=48&&a<=57&&(t+="_"),t+e}return e},viewToString:function(t){for(var e,a=t;a;)e=e?a.id+"."+e:a.id,a=a.parent;return e},copy:function(t,e,a){return o.copy(t,e,a),h.copy||(h.copy=!0,console.warn("Hilo.copy has been Deprecated! Use Hilo.util.copy instead.")),t},browser:r,event:{POINTER_START:r.POINTER_START,POINTER_MOVE:r.POINTER_MOVE,POINTER_END:r.POINTER_END},align:{TOP_LEFT:"TL",TOP:"T",TOP_RIGHT:"TR",LEFT:"L",CENTER:"C",RIGHT:"R",BOTTOM_LEFT:"BL",BOTTOM:"B",BOTTOM_RIGHT:"BR"},getElementRect:function(t){var e;try{e=t.getBoundingClientRect()}catch(a){e={top:t.offsetTop,left:t.offsetLeft,right:t.offsetLeft+t.offsetWidth,bottom:t.offsetTop+t.offsetHeight}}var r=(n.pageXOffset||s.scrollLeft)-(s.clientLeft||0)||0,o=(n.pageYOffset||s.scrollTop)-(s.clientTop||0)||0,i=n.getComputedStyle?getComputedStyle(t):t.currentStyle,c=parseInt,h=c(i.paddingLeft)+c(i.borderLeftWidth)||0,f=c(i.paddingTop)+c(i.borderTopWidth)||0,d=c(i.paddingRight)+c(i.borderRightWidth)||0,l=c(i.paddingBottom)+c(i.borderBottomWidth)||0,g=e.top||0,p=e.left||0,m=e.right||0,T=e.bottom||0;return{left:p+r+h,top:g+o+f,width:m-d-p-h,height:T-l-g-f}},createElement:function(t,e){var a,r,o,n=i.createElement(t);for(a in e)if(r=e[a],"style"===a)for(o in r)n.style[o]=r[o];else n[a]=r;return n},getElement:function(t){return i.getElementById(t)},setElementStyleByView:function(t){var e=t.drawable,a=e.domElement.style,r=t._stateCache||(t._stateCache={}),o=f.browser.jsVendor,n="px",i=!1;if(this.cacheStateIfChanged(t,["visible"],r)&&(a.display=t.visible?"":"none"),this.cacheStateIfChanged(t,["alpha"],r)&&(a.opacity=t.alpha),t.visible&&!(t.alpha<=0)){if(this.cacheStateIfChanged(t,["width"],r)&&(a.width=t.width+n),this.cacheStateIfChanged(t,["height"],r)&&(a.height=t.height+n),this.cacheStateIfChanged(t,["depth"],r)&&(a.zIndex=t.depth+1),t.transform){var s=t.transform;(i=this.cacheStateIfChanged(t,["pivotX","pivotY"],r))&&(a[o+"TransformOrigin"]="0 0"),a[o+"Transform"]="matrix3d("+s.a+", "+s.b+", 0, 0, "+s.c+", "+s.d+", 0, 0, 0, 0, 1, 0, "+s.tx+", "+s.ty+", 0, 1)"}else(i=this.cacheStateIfChanged(t,["pivotX","pivotY"],r))&&(a[o+"TransformOrigin"]=t.pivotX+n+" "+t.pivotY+n),(this.cacheStateIfChanged(t,["x","y","rotation","scaleX","scaleY"],r)||i)&&(a[o+"Transform"]=this.getTransformCSS(t));this.cacheStateIfChanged(t,["background"],r)&&(a.backgroundColor=t.background),a.pointerEvents||(a.pointerEvents="none");var c=e.image;if(c){var h=c.src;h!==r.image&&(r.image=h,a.backgroundImage="url("+h+")");var d=e.rect;if(d){var l=d[0],g=d[1];l!==r.sx&&(r.sx=l,a.backgroundPositionX=-l+n),g!==r.sy&&(r.sy=g,a.backgroundPositionY=-g+n)}}var p=t.mask;if(p){var m=p.drawable.domElement.style.backgroundImage;m!==r.maskImage&&(r.maskImage=m,a[o+"MaskImage"]=m,a[o+"MaskRepeat"]="no-repeat");var T=p.x,u=p.y;T===r.maskX&&u===r.maskY||(r.maskX=T,r.maskY=u,a[o+"MaskPosition"]=T+n+" "+u+n)}}},cacheStateIfChanged:function(t,e,a){var r,o,n,i,s=!1;for(r=0,o=e.length;r=48&&a<=57&&(t+="_"),t+e}return e},viewToString:function(t){for(var e,a=t;a;)e=e?a.id+"."+e:a.id,a=a.parent;return e},copy:function(t,e,a){return o.copy(t,e,a),h.copy||(h.copy=!0,console.warn("Hilo.copy has been Deprecated! Use Hilo.util.copy instead.")),t},browser:r,event:{POINTER_START:r.POINTER_START,POINTER_MOVE:r.POINTER_MOVE,POINTER_END:r.POINTER_END},align:{TOP_LEFT:"TL",TOP:"T",TOP_RIGHT:"TR",LEFT:"L",CENTER:"C",RIGHT:"R",BOTTOM_LEFT:"BL",BOTTOM:"B",BOTTOM_RIGHT:"BR"},getElementRect:function(t){var e;try{e=t.getBoundingClientRect()}catch(a){e={top:t.offsetTop,left:t.offsetLeft,right:t.offsetLeft+t.offsetWidth,bottom:t.offsetTop+t.offsetHeight}}var r=(n.pageXOffset||s.scrollLeft)-(s.clientLeft||0)||0,o=(n.pageYOffset||s.scrollTop)-(s.clientTop||0)||0,i=n.getComputedStyle?getComputedStyle(t):t.currentStyle,c=parseInt,h=c(i.paddingLeft)+c(i.borderLeftWidth)||0,f=c(i.paddingTop)+c(i.borderTopWidth)||0,d=c(i.paddingRight)+c(i.borderRightWidth)||0,l=c(i.paddingBottom)+c(i.borderBottomWidth)||0,g=e.top||0,p=e.left||0,m=e.right||0,T=e.bottom||0;return{left:p+r+h,top:g+o+f,width:m-d-p-h,height:T-l-g-f}},createElement:function(t,e){var a,r,o,n=i.createElement(t);for(a in e)if(r=e[a],"style"===a)for(o in r)n.style[o]=r[o];else n[a]=r;return n},getElement:function(t){return i.getElementById(t)},setElementStyleByView:function(t){var e=t.drawable,a=e.domElement.style,r=t._stateCache||(t._stateCache={}),o=f.browser.jsVendor,n="px",i=!1;if(this.cacheStateIfChanged(t,["visible"],r)&&(a.display=t.visible?"":"none"),this.cacheStateIfChanged(t,["alpha"],r)&&(a.opacity=t.alpha),t.visible&&!(t.alpha<=0)){if(this.cacheStateIfChanged(t,["width"],r)&&(a.width=t.width+n),this.cacheStateIfChanged(t,["height"],r)&&(a.height=t.height+n),this.cacheStateIfChanged(t,["depth"],r)&&(a.zIndex=t.depth+1),t.transform){var s=t.transform;(i=this.cacheStateIfChanged(t,["pivotX","pivotY"],r))&&(a[o+"TransformOrigin"]="0 0"),a[o+"Transform"]="matrix3d("+s.a+", "+s.b+", 0, 0, "+s.c+", "+s.d+", 0, 0, 0, 0, 1, 0, "+s.tx+", "+s.ty+", 0, 1)"}else(i=this.cacheStateIfChanged(t,["pivotX","pivotY"],r))&&(a[o+"TransformOrigin"]=t.pivotX+n+" "+t.pivotY+n),(this.cacheStateIfChanged(t,["x","y","rotation","scaleX","scaleY"],r)||i)&&(a[o+"Transform"]=this.getTransformCSS(t));this.cacheStateIfChanged(t,["background"],r)&&(a.backgroundColor=t.background),a.pointerEvents||(a.pointerEvents="none");var c=e.image;if(c){var h=c.src;h!==r.image&&(r.image=h,a.backgroundImage="url("+h+")");var d=e.rect;if(d){var l=d[0],g=d[1];l!==r.sx&&(r.sx=l,a.backgroundPositionX=-l+n),g!==r.sy&&(r.sy=g,a.backgroundPositionY=-g+n)}}var p=t.mask;if(p){var m=p.drawable.domElement.style.backgroundImage;m!==r.maskImage&&(r.maskImage=m,a[o+"MaskImage"]=m,a[o+"MaskRepeat"]="no-repeat");var T=p.x,u=p.y;T===r.maskX&&u===r.maskY||(r.maskX=T,r.maskY=u,a[o+"MaskPosition"]=T+n+" "+u+n)}}},cacheStateIfChanged:function(t,e,a){var r,o,n,i,s=!1;for(r=0,o=e.length;r=o)return void e.fire("complete");if(e._currentIndex=n)return void e.fire("complete");if(e._currentIndex=48&&a<=57&&(e+="_"),e+t}return t},viewToString:function(e){for(var t,a=e;a;)t=t?a.id+"."+t:a.id,a=a.parent;return t},copy:function(e,t,a){return util.copy(e,t,a),hasWarnedDict.copy||(hasWarnedDict.copy=!0,console.warn("Hilo.copy has been Deprecated! Use Hilo.util.copy instead.")),e},browser:browser,event:{POINTER_START:browser.POINTER_START,POINTER_MOVE:browser.POINTER_MOVE,POINTER_END:browser.POINTER_END},align:{TOP_LEFT:"TL",TOP:"T",TOP_RIGHT:"TR",LEFT:"L",CENTER:"C",RIGHT:"R",BOTTOM_LEFT:"BL",BOTTOM:"B",BOTTOM_RIGHT:"BR"},getElementRect:function(e){var t;try{t=e.getBoundingClientRect()}catch(a){t={top:e.offsetTop,left:e.offsetLeft,right:e.offsetLeft+e.offsetWidth,bottom:e.offsetTop+e.offsetHeight}}var r=(win.pageXOffset||docElem.scrollLeft)-(docElem.clientLeft||0)||0,o=(win.pageYOffset||docElem.scrollTop)-(docElem.clientTop||0)||0,i=win.getComputedStyle?getComputedStyle(e):e.currentStyle,n=parseInt,s=n(i.paddingLeft)+n(i.borderLeftWidth)||0,c=n(i.paddingTop)+n(i.borderTopWidth)||0,d=n(i.paddingRight)+n(i.borderRightWidth)||0,h=n(i.paddingBottom)+n(i.borderBottomWidth)||0,l=t.top||0,f=t.left||0,g=t.right||0,p=t.bottom||0;return{left:f+r+s,top:l+o+c,width:g-d-f-s,height:p-h-l-c}},createElement:function(e,t){var a,r,o,i=doc.createElement(e);for(a in t)if(r=t[a],"style"===a)for(o in r)i.style[o]=r[o];else i[a]=r;return i},getElement:function(e){return doc.getElementById(e)},setElementStyleByView:function(e){var t=e.drawable,a=t.domElement.style,r=e._stateCache||(e._stateCache={}),o=Hilo.browser.jsVendor,i="px",n=!1;if(this.cacheStateIfChanged(e,["visible"],r)&&(a.display=e.visible?"":"none"),this.cacheStateIfChanged(e,["alpha"],r)&&(a.opacity=e.alpha),e.visible&&!(e.alpha<=0)){if(this.cacheStateIfChanged(e,["width"],r)&&(a.width=e.width+i),this.cacheStateIfChanged(e,["height"],r)&&(a.height=e.height+i),this.cacheStateIfChanged(e,["depth"],r)&&(a.zIndex=e.depth+1),e.transform){var s=e.transform;(n=this.cacheStateIfChanged(e,["pivotX","pivotY"],r))&&(a[o+"TransformOrigin"]="0 0"),a[o+"Transform"]="matrix3d("+s.a+", "+s.b+", 0, 0, "+s.c+", "+s.d+", 0, 0, 0, 0, 1, 0, "+s.tx+", "+s.ty+", 0, 1)"}else(n=this.cacheStateIfChanged(e,["pivotX","pivotY"],r))&&(a[o+"TransformOrigin"]=e.pivotX+i+" "+e.pivotY+i),(this.cacheStateIfChanged(e,["x","y","rotation","scaleX","scaleY"],r)||n)&&(a[o+"Transform"]=this.getTransformCSS(e));this.cacheStateIfChanged(e,["background"],r)&&(a.backgroundColor=e.background),a.pointerEvents||(a.pointerEvents="none");var c=t.image;if(c){var d=c.src;d!==r.image&&(r.image=d,a.backgroundImage="url("+d+")");var h=t.rect;if(h){var l=h[0],f=h[1];l!==r.sx&&(r.sx=l,a.backgroundPositionX=-l+i),f!==r.sy&&(r.sy=f,a.backgroundPositionY=-f+i)}}var g=e.mask;if(g){var p=g.drawable.domElement.style.backgroundImage;p!==r.maskImage&&(r.maskImage=p,a[o+"MaskImage"]=p,a[o+"MaskRepeat"]="no-repeat");var m=g.x,u=g.y;m===r.maskX&&u===r.maskY||(r.maskX=m,r.maskY=u,a[o+"MaskPosition"]=m+i+" "+u+i)}}},cacheStateIfChanged:function(e,t,a){var r,o,i,n,s=!1;for(r=0,o=t.length;r=48&&a<=57&&(e+="_"),e+t}return t},viewToString:function(e){for(var t,a=e;a;)t=t?a.id+"."+t:a.id,a=a.parent;return t},copy:function(e,t,a){return util.copy(e,t,a),hasWarnedDict.copy||(hasWarnedDict.copy=!0,console.warn("Hilo.copy has been Deprecated! Use Hilo.util.copy instead.")),e},browser:browser,event:{POINTER_START:browser.POINTER_START,POINTER_MOVE:browser.POINTER_MOVE,POINTER_END:browser.POINTER_END},align:{TOP_LEFT:"TL",TOP:"T",TOP_RIGHT:"TR",LEFT:"L",CENTER:"C",RIGHT:"R",BOTTOM_LEFT:"BL",BOTTOM:"B",BOTTOM_RIGHT:"BR"},getElementRect:function(e){var t;try{t=e.getBoundingClientRect()}catch(a){t={top:e.offsetTop,left:e.offsetLeft,right:e.offsetLeft+e.offsetWidth,bottom:e.offsetTop+e.offsetHeight}}var r=(win.pageXOffset||docElem.scrollLeft)-(docElem.clientLeft||0)||0,o=(win.pageYOffset||docElem.scrollTop)-(docElem.clientTop||0)||0,i=win.getComputedStyle?getComputedStyle(e):e.currentStyle,n=parseInt,s=n(i.paddingLeft)+n(i.borderLeftWidth)||0,c=n(i.paddingTop)+n(i.borderTopWidth)||0,d=n(i.paddingRight)+n(i.borderRightWidth)||0,h=n(i.paddingBottom)+n(i.borderBottomWidth)||0,l=t.top||0,f=t.left||0,g=t.right||0,p=t.bottom||0;return{left:f+r+s,top:l+o+c,width:g-d-f-s,height:p-h-l-c}},createElement:function(e,t){var a,r,o,i=doc.createElement(e);for(a in t)if(r=t[a],"style"===a)for(o in r)i.style[o]=r[o];else i[a]=r;return i},getElement:function(e){return doc.getElementById(e)},setElementStyleByView:function(e){var t=e.drawable,a=t.domElement.style,r=e._stateCache||(e._stateCache={}),o=Hilo.browser.jsVendor,i="px",n=!1;if(this.cacheStateIfChanged(e,["visible"],r)&&(a.display=e.visible?"":"none"),this.cacheStateIfChanged(e,["alpha"],r)&&(a.opacity=e.alpha),e.visible&&!(e.alpha<=0)){if(this.cacheStateIfChanged(e,["width"],r)&&(a.width=e.width+i),this.cacheStateIfChanged(e,["height"],r)&&(a.height=e.height+i),this.cacheStateIfChanged(e,["depth"],r)&&(a.zIndex=e.depth+1),e.transform){var s=e.transform;(n=this.cacheStateIfChanged(e,["pivotX","pivotY"],r))&&(a[o+"TransformOrigin"]="0 0"),a[o+"Transform"]="matrix3d("+s.a+", "+s.b+", 0, 0, "+s.c+", "+s.d+", 0, 0, 0, 0, 1, 0, "+s.tx+", "+s.ty+", 0, 1)"}else(n=this.cacheStateIfChanged(e,["pivotX","pivotY"],r))&&(a[o+"TransformOrigin"]=e.pivotX+i+" "+e.pivotY+i),(this.cacheStateIfChanged(e,["x","y","rotation","scaleX","scaleY"],r)||n)&&(a[o+"Transform"]=this.getTransformCSS(e));this.cacheStateIfChanged(e,["background"],r)&&(a.backgroundColor=e.background),a.pointerEvents||(a.pointerEvents="none");var c=t.image;if(c){var d=c.src;d!==r.image&&(r.image=d,a.backgroundImage="url("+d+")");var h=t.rect;if(h){var l=h[0],f=h[1];l!==r.sx&&(r.sx=l,a.backgroundPositionX=-l+i),f!==r.sy&&(r.sy=f,a.backgroundPositionY=-f+i)}}var g=e.mask;if(g){var p=g.drawable.domElement.style.backgroundImage;p!==r.maskImage&&(r.maskImage=p,a[o+"MaskImage"]=p,a[o+"MaskRepeat"]="no-repeat");var m=g.x,u=g.y;m===r.maskX&&u===r.maskY||(r.maskX=m,r.maskY=u,a[o+"MaskPosition"]=m+i+" "+u+i)}}},cacheStateIfChanged:function(e,t,a){var r,o,i,n,s=!1;for(r=0,o=t.length;r=n)return void e.fire("complete");if(e._currentIndex=n)return void e.fire("complete");if(e._currentIndex=48&&i<=57&&(t+="_"),t+e}return e},viewToString:function(t){for(var e,i=t;i;)e=e?i.id+"."+e:i.id,i=i.parent;return e},copy:function(t,e,r){return i.copy(t,e,r),s.copy||(s.copy=!0,console.warn("Hilo.copy has been Deprecated! Use Hilo.util.copy instead.")),t},browser:e,event:{POINTER_START:e.POINTER_START,POINTER_MOVE:e.POINTER_MOVE,POINTER_END:e.POINTER_END},align:{TOP_LEFT:"TL",TOP:"T",TOP_RIGHT:"TR",LEFT:"L",CENTER:"C",RIGHT:"R",BOTTOM_LEFT:"BL",BOTTOM:"B",BOTTOM_RIGHT:"BR"},getElementRect:function(t){var e;try{e=t.getBoundingClientRect()}catch(i){e={top:t.offsetTop,left:t.offsetLeft,right:t.offsetLeft+t.offsetWidth,bottom:t.offsetTop+t.offsetHeight}}var n=(r.pageXOffset||a.scrollLeft)-(a.clientLeft||0)||0,o=(r.pageYOffset||a.scrollTop)-(a.clientTop||0)||0,s=r.getComputedStyle?getComputedStyle(t):t.currentStyle,h=parseInt,l=h(s.paddingLeft)+h(s.borderLeftWidth)||0,c=h(s.paddingTop)+h(s.borderTopWidth)||0,u=h(s.paddingRight)+h(s.borderRightWidth)||0,d=h(s.paddingBottom)+h(s.borderBottomWidth)||0,f=e.top||0,p=e.left||0,v=e.right||0,m=e.bottom||0;return{left:p+n+l,top:f+o+c,width:v-u-p-l,height:m-d-f-c}},createElement:function(t,e){var i,r,a,o=n.createElement(t);for(i in e)if(r=e[i],"style"===i)for(a in r)o.style[a]=r[a];else o[i]=r;return o},getElement:function(t){return n.getElementById(t)},setElementStyleByView:function(t){var e=t.drawable,i=e.domElement.style,r=t._stateCache||(t._stateCache={}),n=h.browser.jsVendor,a="px",o=!1;if(this.cacheStateIfChanged(t,["visible"],r)&&(i.display=t.visible?"":"none"),this.cacheStateIfChanged(t,["alpha"],r)&&(i.opacity=t.alpha),t.visible&&!(t.alpha<=0)){if(this.cacheStateIfChanged(t,["width"],r)&&(i.width=t.width+a),this.cacheStateIfChanged(t,["height"],r)&&(i.height=t.height+a),this.cacheStateIfChanged(t,["depth"],r)&&(i.zIndex=t.depth+1),t.transform){var s=t.transform;(o=this.cacheStateIfChanged(t,["pivotX","pivotY"],r))&&(i[n+"TransformOrigin"]="0 0"),i[n+"Transform"]="matrix3d("+s.a+", "+s.b+", 0, 0, "+s.c+", "+s.d+", 0, 0, 0, 0, 1, 0, "+s.tx+", "+s.ty+", 0, 1)"}else(o=this.cacheStateIfChanged(t,["pivotX","pivotY"],r))&&(i[n+"TransformOrigin"]=t.pivotX+a+" "+t.pivotY+a),(this.cacheStateIfChanged(t,["x","y","rotation","scaleX","scaleY"],r)||o)&&(i[n+"Transform"]=this.getTransformCSS(t));this.cacheStateIfChanged(t,["background"],r)&&(i.backgroundColor=t.background),i.pointerEvents||(i.pointerEvents="none");var l=e.image;if(l){var c=l.src;c!==r.image&&(r.image=c,i.backgroundImage="url("+c+")");var u=e.rect;if(u){var d=u[0],f=u[1];d!==r.sx&&(r.sx=d,i.backgroundPositionX=-d+a),f!==r.sy&&(r.sy=f,i.backgroundPositionY=-f+a)}}var p=t.mask;if(p){var v=p.drawable.domElement.style.backgroundImage;v!==r.maskImage&&(r.maskImage=v,i[n+"MaskImage"]=v,i[n+"MaskRepeat"]="no-repeat");var m=p.x,g=p.y;m===r.maskX&&g===r.maskY||(r.maskX=m,r.maskY=g,i[n+"MaskPosition"]=m+a+" "+g+a)}}},cacheStateIfChanged:function(t,e,i){var r,n,a,o,s=!1;for(r=0,n=e.length;r=6?(e=s[0],i=s[1],r=s[2],n=s[3],a=s[4],o=s[5]):(e=t.a,i=t.b,r=t.c,n=t.d,a=t.tx,o=t.ty),this.a=h*e+l*r,this.b=h*i+l*n,this.c=c*e+u*r,this.d=c*i+u*n,this.tx=d*e+f*r+a,this.ty=d*i+f*n+o,this},rotate:function(t){var e=Math.sin(t),i=Math.cos(t),r=this.a,n=this.b,a=this.c,o=this.d,s=this.tx,h=this.ty;return this.a=r*i-n*e,this.b=r*e+n*i,this.c=a*i-o*e,this.d=a*e+o*i,this.tx=s*i-h*e,this.ty=s*e+h*i,this},scale:function(t,e){return this.a*=t,this.d*=e,this.c*=t,this.b*=e,this.tx*=t,this.ty*=e,this},translate:function(t,e){return this.tx+=t,this.ty+=e,this},identity:function(){return this.a=this.d=1,this.b=this.c=this.tx=this.ty=0,this},invert:function(){var t=this.a,e=this.b,i=this.c,r=this.d,n=this.tx,a=t*r-e*i;return this.a=r/a,this.b=-e/a,this.c=-i/a,this.d=t/a,this.tx=(i*this.ty-r*n)/a,this.ty=-(t*this.ty-e*n)/a,this},transformPoint:function(t,e,i){var r=t.x*this.a+t.y*this.c+this.tx,n=t.x*this.b+t.y*this.d+this.ty;return e&&(r=r+.5>>0,n=n+.5>>0),i?{x:r,y:n}:(t.x=r,t.y=n,t)}});return i},{requires:["hilo/core/Class"]}),KISSY.add("hilo/event/EventMixin",function(t,e){var i={_listeners:null,on:function(t,e,i){for(var r=this._listeners=this._listeners||{},n=r[t]=r[t]||[],a=0,o=n.length;a-1&&o.splice(c,1)}}return 0==o.length&&delete a[n],!0}return!1}},r=e.create({constructor:function(t,e,i){this.type=t,this.target=e,this.detail=i,this.timeStamp=+new Date},type:null,target:null,detail:null,timeStamp:0,stopImmediatePropagation:function(){this._stopped=!0}}),n=window.Event;if(n){var a=n.prototype,o=a.stopImmediatePropagation;a.stopImmediatePropagation=function(){o&&o.call(this),this._stopped=!0}}return i},{requires:["hilo/core/Class"]}),KISSY.add("hilo/view/Drawable",function(t,e,i){var r=e.create({constructor:function(t){this.init(t)},image:null,rect:null,init:function(t){var e=this,n=e.image;r.isDrawable(t)?e.image=t:i.copy(e,t,!0);var a=e.image;if("string"==typeof a){if(!n||a!==n.getAttribute("src")){e.image=null;var o=new Image;return t.crossOrigin&&(o.crossOrigin="Anonymous"),o.onload=function(){o.onload=null,e.init(o)},void(o.src=a)}a=e.image=n}a&&!e.rect&&(e.rect=[0,0,a.width,a.height])},Statics:{isDrawable:function(t){if(!t||!t.tagName)return!1;var e=t.tagName.toLowerCase();return"img"===e||"canvas"===e||"video"===e}}});return r},{requires:["hilo/core/Class","hilo/util/util"]}),KISSY.add("hilo/renderer/Renderer",function(t,e,i){var r=e.create({constructor:function(t){t=t||{},i.copy(this,t,!0)},renderType:null,canvas:null,stage:null,blendMode:"source-over",startDraw:function(t){},draw:function(t){},endDraw:function(t){},transform:function(){},hide:function(){},remove:function(t){},clear:function(t,e,i,r){},resize:function(t,e){}});return r},{requires:["hilo/core/Class","hilo/util/util"]}),KISSY.add("hilo/renderer/CanvasRenderer",function(t,e,i,r){var n=e.create({Extends:r,constructor:function(t){n.superclass.constructor.call(this,t),this.context=this.canvas.getContext("2d")},renderType:"canvas",context:null,startDraw:function(t){return!!(t.visible&&t.alpha>0)&&(t===this.stage&&this.context.clearRect(0,0,t.width,t.height),t.blendMode!==this.blendMode&&(this.context.globalCompositeOperation=this.blendMode=t.blendMode),this.context.save(),!0)},draw:function(t){var e=this.context,i=t.width,r=t.height,n=t.background;n&&(e.fillStyle=n,e.fillRect(0,0,i,r));var a=t.drawable,o=a&&a.image;if(o){var s=a.rect,h=s[2],l=s[3],c=s[4],u=s[5];if(!h||!l)return;i||r||(i=t.width=h,r=t.height=l),(c||u)&&e.translate(c-.5*h,u-.5*l),e.drawImage(o,s[0],s[1],h,l,0,0,i,r)}},endDraw:function(t){this.context.restore()},transform:function(t){var e=t.drawable;if(e&&e.domElement)return void i.setElementStyleByView(t);var r=this.context,n=t.scaleX,a=t.scaleY;if(t===this.stage){var o=this.canvas.style,s=t._scaleX,h=t._scaleY,l=!1;(!s&&1!=n||s&&s!=n)&&(t._scaleX=n,o.width=n*t.width+"px",l=!0),(!h&&1!=a||h&&h!=a)&&(t._scaleY=a,o.height=a*t.height+"px",l=!0),l&&t.updateViewport()}else{var c=t.x,u=t.y,d=t.pivotX,f=t.pivotY,p=t.rotation%360,v=t.transform,m=t.mask;m&&(m._render(this),r.clip());var g=t.align;if(g){var _=t.getAlignPosition();c=_.x,u=_.y}v?r.transform(v.a,v.b,v.c,v.d,v.tx,v.ty):(0==c&&0==u||r.translate(c,u),0!=p&&r.rotate(p*Math.PI/180),1==n&&1==a||r.scale(n,a),0==d&&0==f||r.translate(-d,-f))}t.alpha>0&&(r.globalAlpha*=t.alpha)},remove:function(t){var e=t.drawable,i=e&&e.domElement;if(i){var r=i.parentNode;r&&r.removeChild(i)}},clear:function(t,e,i,r){this.context.clearRect(t,e,i,r)},resize:function(t,e){var i=this.canvas,r=this.stage,n=i.style;i.width=t,i.height=e,n.width=r.width*r.scaleX+"px",n.height=r.height*r.scaleY+"px"}});return n},{requires:["hilo/core/Class","hilo/core/Hilo","hilo/renderer/Renderer"]}),KISSY.add("hilo/renderer/DOMRenderer",function(t,e,i,r,n){var a=function(){function t(t,e){var r=t.tagName||"div",n=e.image,a=t.width||n&&n.width,o=t.height||n&&n.height,s=i.createElement(r),h=s.style;if(t.id&&(s.id=t.id),h.position="absolute",h.left=(t.left||0)+"px",h.top=(t.top||0)+"px",h.width=a+"px",h.height=o+"px","canvas"==r){if(s.width=a,s.height=o,n){var l=s.getContext("2d"),c=e.rect||[0,0,a,o];l.drawImage(n,c[0],c[1],c[2],c[3],t.x||0,t.y||0,t.width||c[2],t.height||c[3])}}else if(h.opacity=void 0!=t.alpha?t.alpha:1,(t===this.stage||t.clipChildren)&&(h.overflow="hidden"),n&&n.src){h.backgroundImage="url("+n.src+")";var u=t.rectX||0,d=t.rectY||0;h.backgroundPosition=-u+"px "+-d+"px"}return s}return e.create({Extends:r,constructor:function(t){a.superclass.constructor.call(this,t)},renderType:"dom",startDraw:function(e){var i=e.drawable=e.drawable||new n;return i.domElement=i.domElement||t(e,i),!0},draw:function(t){var e=t.parent,i=t.drawable.domElement,r=i.parentNode;if(e){var n=e.drawable.domElement;if(n!=r&&n.appendChild(i),!t.width&&!t.height){var a=t.drawable.rect;a&&(a[2]||a[3])&&(t.width=a[2],t.height=a[3])}}else t!==this.stage||r||(i.style.overflow="hidden",this.canvas.appendChild(i))},transform:function(t){if(i.setElementStyleByView(t),t===this.stage){var e=this.canvas.style,r=t._scaleX,n=t._scaleY,a=t.scaleX,o=t.scaleY;(!r&&1!=a||r&&r!=a)&&(t._scaleX=a,e.width=a*t.width+"px"),(!n&&1!=o||n&&n!=o)&&(t._scaleY=o,e.height=o*t.height+"px")}},remove:function(t){var e=t.drawable,i=e&&e.domElement;if(i){var r=i.parentNode;r&&r.removeChild(i)}},hide:function(t){var e=t.drawable&&t.drawable.domElement;e&&(e.style.display="none")},resize:function(t,e){var i=this.canvas.style;i.width=t+"px",i.height=e+"px","absolute"!=i.position&&(i.position="relative")}})}();return a},{requires:["hilo/core/Class","hilo/core/Hilo","hilo/renderer/Renderer","hilo/view/Drawable"]}),KISSY.add("hilo/renderer/WebGLRenderer",function(t,e,i,r,n){var a=Math.PI/180,o=e.create({Extends:r,Statics:{MAX_BATCH_NUM:2e3,ATTRIBUTE_NUM:5,isSupport:function(){if(void 0==this._isSupported){var t=document.createElement("canvas");t.getContext&&(t.getContext("webgl")||t.getContext("experimental-webgl"))?this._isSupported=!0:this._isSupported=!1}return this._isSupported},contextOptions:null},renderType:"webgl",gl:null,_isContextLost:!1,_cacheTexture:{},constructor:function(t){o.superclass.constructor.call(this,t);var e=this,i=o.contextOptions||{};this.gl=this.canvas.getContext("webgl",i)||this.canvas.getContext("experimental-webgl",i),this.maxBatchNum=o.MAX_BATCH_NUM,this.positionStride=4*o.ATTRIBUTE_NUM;var r=this.maxBatchNum*o.ATTRIBUTE_NUM*4,n=6*this.maxBatchNum;this.arrayBuffer=new ArrayBuffer(4*r),this.float32Array=new Float32Array(this.arrayBuffer),this.uint32Array=new Uint32Array(this.arrayBuffer),this.indexs=new Uint16Array(n);for(var a=0,s=0;a0)&&(t===this.stage&&this.clear(),!0)},draw:function(t){var e=t.width,i=t.height,r=(t.background,t.drawable),n=r&&r.image;if(n){var a=r.rect,o=a[2],s=a[3];e||i||(e=t.width=o,i=t.height=s),this.batchIndex>=this.maxBatchNum&&this._renderBatches();var h=this._createVertexs(n,a[0],a[1],o,s,0,0,e,i),l=this.batchIndex*this.positionStride,c=this.float32Array,u=this.uint32Array,d=(t.tint>>16)+(65280&t.tint)+((255&t.tint)<<16)+(255*t.__webglRenderAlpha<<24);c[l+0]=h[0],c[l+1]=h[1],c[l+2]=h[2],c[l+3]=h[3],u[l+4]=d,c[l+5]=h[4],c[l+6]=h[5],c[l+7]=h[6],c[l+8]=h[7],u[l+9]=d,c[l+10]=h[8],c[l+11]=h[9],c[l+12]=h[10],c[l+13]=h[11],u[l+14]=d,c[l+15]=h[12],c[l+16]=h[13],c[l+17]=h[14],c[l+18]=h[15],u[l+19]=d;for(var f=t.__webglWorldMatrix,p=0;p<4;p++){var v=c[l+5*p],m=c[l+5*p+1];c[l+5*p]=f.a*v+f.c*m+f.tx,c[l+5*p+1]=f.b*v+f.d*m+f.ty}t.__textureImage=n,this.sprites[this.batchIndex++]=t}},endDraw:function(t){t===this.stage&&this._renderBatches()},transform:function(t){var e=t.drawable;if(e&&e.domElement)return void i.setElementStyleByView(t);var r=t.scaleX,a=t.scaleY;if(t===this.stage){var o=this.canvas.style,s=t._scaleX,h=t._scaleY,l=!1;(!s&&1!=r||s&&s!=r)&&(t._scaleX=r,o.width=r*t.width+"px",l=!0),(!h&&1!=a||h&&h!=a)&&(t._scaleY=a,o.height=a*t.height+"px",l=!0),l&&t.updateViewport(),t.__webglWorldMatrix=t.__webglWorldMatrix||new n(1,0,0,1,0,0)}else t.parent&&(t.__webglWorldMatrix=t.__webglWorldMatrix||new n(1,0,0,1,0,0),this._setConcatenatedMatrix(t,t.parent));t.alpha>0&&(t.parent&&t.parent.__webglRenderAlpha?t.__webglRenderAlpha=t.alpha*t.parent.__webglRenderAlpha:t.__webglRenderAlpha=t.alpha)},remove:function(t){var e=t.drawable,i=e&&e.domElement;if(i){var r=i.parentNode;r&&r.removeChild(i)}},clear:function(t,e,i,r){this.gl.clear(this.gl.COLOR_BUFFER_BIT)},resize:function(t,e){if(this.width!==t||this.height!==e){var i=this.canvas,r=this.stage,n=i.style;this.width=i.width=t,this.height=i.height=e,n.width=r.width*r.scaleX+"px",n.height=r.height*r.scaleY+"px",this.gl.viewport(0,0,t,e),this.canvasHalfWidth=.5*t,this.canvasHalfHeight=.5*e,this._uploadProjectionTransform(!0)}},_renderBatches:function(){var t=this.gl;t.bufferSubData(t.ARRAY_BUFFER,0,this.uint32Array.subarray(0,this.batchIndex*this.positionStride));for(var e=0,i=0,r=null,n=0;n0&&(i.bindTexture(i.TEXTURE_2D,this._getTexture(this.sprites[t])),i.drawElements(i.TRIANGLES,6*r,i.UNSIGNED_SHORT,6*t*2))},_uploadProjectionTransform:function(t){this._projectionTransformElements&&!t||(this._projectionTransformElements=new Float32Array([1/this.canvasHalfWidth,0,0,0,-1/this.canvasHalfHeight,0,-1,1,1])),this.gl.uniformMatrix3fv(this.u_projectionTransform,!1,this._projectionTransformElements)},_initShaders:function(){var t=" attribute vec2 a_position;\n attribute vec2 a_TexCoord;\n attribute vec4 a_tint;\n uniform mat3 u_projectionTransform;\n varying vec2 v_TexCoord;\n varying vec4 v_tint;\n void main(){\n gl_Position = vec4((u_projectionTransform * vec3(a_position, 1.0)).xy, 1.0, 1.0);\n v_TexCoord = a_TexCoord;\n v_tint = vec4(a_tint.rgb * a_tint.a, a_tint.a);\n }\n ",e="\n precision mediump float;\n uniform sampler2D u_Sampler;\n varying vec2 v_TexCoord;\n varying vec4 v_tint;\n void main(){\n gl_FragColor = texture2D(u_Sampler, v_TexCoord) * v_tint;\n }\n ";this.defaultShader=new s(this,{v:t,f:e},{attributes:["a_position","a_TexCoord","a_tint"],uniforms:["u_projectionTransform","u_Sampler"]})},_createVertexs:function(t,e,i,r,n,a,o,s,h){var l=this.__tempVertexs||[],c=t.width,u=t.height;r/=c,n/=u,e/=c,i/=u,s=s,h=h,a=a,o=o,r+e>1&&(r=1-e),n+i>1&&(n=1-i);var d=0;return l[d++]=a,l[d++]=o,l[d++]=e,l[d++]=i,l[d++]=a+s,l[d++]=o,l[d++]=e+r,l[d++]=i,l[d++]=a,l[d++]=o+h,l[d++]=e,l[d++]=i+n,l[d++]=a+s,l[d++]=o+h,l[d++]=e+r,l[d++]=i+n,l},_setConcatenatedMatrix:function(t,e){var i=t.__webglWorldMatrix,r=1,n=0,o=t.rotation%360,s=t.pivotX,h=t.pivotY,l=t.scaleX,c=t.scaleY,u=t.transform;if(u)i.copy(u);else{if(o){var d=o*a;r=Math.cos(d),n=Math.sin(d)}var f=t.getAlignPosition();i.a=r*l,i.b=n*l,i.c=-n*c,i.d=r*c,i.tx=f.x-i.a*s-i.c*h,i.ty=f.y-i.b*s-i.d*h}i.concat(e.__webglWorldMatrix)},_getTexture:function(t){var e=t.__textureImage,i=this._cacheTexture[e.src];return i||(i=this.activeShader.uploadTexture(e)),i}}),s=function(t,e,i){this.renderer=t,this.gl=t.gl,this.program=this._createProgram(this.gl,e.v,e.f),i=i||{},this.attributes=i.attributes||[],this.uniforms=i.uniforms||[]};return s.prototype={active:function(){var t=this,e=t.renderer,i=t.gl,r=t.program;r&&i&&(e.activeShader=t,i.useProgram(r),t.attributes.forEach(function(t){e[t]=i.getAttribLocation(r,t),i.enableVertexAttribArray(e[t])}),t.uniforms.forEach(function(t){e[t]=i.getUniformLocation(r,t)}),t.width===e.width&&t.height===e.height||(t.width=e.width,t.height=e.height,e._uploadProjectionTransform()))},uploadTexture:function(t){var e=this.gl,i=this.renderer,r=e.createTexture(),n=i.u_Sampler;return e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,r),e.pixelStorei(e.UNPACK_PREMULTIPLY_ALPHA_WEBGL,1),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,t),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.uniform1i(n,0),e.bindTexture(e.TEXTURE_2D,null),this.renderer._cacheTexture[t.src]=r,r},_createProgram:function(t,e,i){var r=this._createShader(t,t.VERTEX_SHADER,e),n=this._createShader(t,t.FRAGMENT_SHADER,i);if(!r||!n)return null;var a=t.createProgram();if(a){t.attachShader(a,r),t.attachShader(a,n),t.linkProgram(a),t.deleteShader(n),t.deleteShader(r);var o=t.getProgramParameter(a,t.LINK_STATUS);if(!o){var s=t.getProgramInfoLog(a);return console.log("Failed to link program: "+s),t.deleteProgram(a),null}}return a},_createShader:function(t,e,i){var r=t.createShader(e);if(r){t.shaderSource(r,i),t.compileShader(r);var n=t.getShaderParameter(r,t.COMPILE_STATUS);if(!n){var a=t.getShaderInfoLog(r);return console.log("Failed to compile shader: "+a),t.deleteShader(r),null}}return r}},o},{requires:["hilo/core/Class","hilo/core/Hilo","hilo/renderer/Renderer","hilo/geom/Matrix"]}),KISSY.add("hilo/view/View",function(t,e,i,r,n,a){var o=function(){function t(t,e,i){for(var r,n,a,o,s=0,h=!1,l=0,c=i.length;ld.x?(r=d.x,n=u.x):(r=u.x,n=d.x),t>=r&&t<=n))h=!0;else if(u.y>d.y?(a=d.y,o=u.y):(a=u.y,o=d.y),!(eo)){var f=(e-u.y)*(d.x-u.x)/(d.y-u.y)+u.x;if(f>t?s++:f==t&&(h=!0),u.x>t&&u.y==e){var p=i[(c+l-1)%c];(p.ye||p.y>e&&d.ys?s=c:cl?l=c:c=0)return!1;u>i.overlap&&(i.overlap=u,i.normal.x=p.x,i.normal.y=p.y)}return i}return i.create({Mixes:r,constructor:function(t){t=t||{},this.id=this.id||t.id||e.getUid("View"),a.copy(this,t,!0)},tint:16777215,id:null,x:0,y:0,width:0,height:0,alpha:1,rotation:0,visible:!0,pivotX:0,pivotY:0,scaleX:1,scaleY:1,pointerEnabled:!0,background:null,mask:null,align:null,drawable:null,boundsArea:null,parent:null,depth:-1,transform:null,blendMode:"source-over",getStage:function(){for(var t,e=this;t=e.parent;)e=t;return e.canvas?e:null},getScaledWidth:function(){return this.width*this.scaleX},getScaledHeight:function(){return this.height*this.scaleY},addTo:function(t,e){return"number"==typeof e?t.addChildAt(this,e):t.addChild(this),this},removeFromParent:function(){var t=this.parent;return t&&t.removeChild(this),this},getBounds:function(){for(var t,e,i,r,n,a,o,s=this.width,h=this.height,l=this.getConcatenatedMatrix(),c=this.boundsArea||[{x:0,y:0},{x:s,y:0},{x:s,y:h},{x:0,y:h}],u=[],d=0,f=c.length;de?r=e:ni?a=i:o>1,r=0;break;case"TR":i=o-n,r=0;break;case"L":i=0,r=s-a>>1;break;case"C":i=o-n>>1,r=s-a>>1;break;case"R":i=o-n,r=s-a>>1;break;case"BL":i=0,r=s-a;break;case"B":i=o-n>>1,r=s-a;break;case"BR":i=o-n,r=s-a}}return{x:i,y:r}},hitTestPoint:function(e,i,r){var n=this.getBounds(),a=e>=n.x&&e<=n.x+n.width&&i>=n.y&&i<=n.y+n.height;return a&&r&&(a=t(e,i,n)),a},hitTestObject:function(t,e){var i=this.getBounds(),r=t.getBounds(),n=i.x<=r.x+r.width&&r.x<=i.x+i.width&&i.y<=r.y+r.height&&r.y<=i.y+i.height;return n&&e&&(n=o(i,r)),!!n},_render:function(t,e){this.onUpdate&&this.onUpdate(e)===!1||!t.startDraw(this)||(t.transform(this),this.render(t,e),t.endDraw(this))},_fireMouseEvent:function(t){if(t.eventCurrentTarget=this,this.fire(t),"mousemove"==t.type){if(!this.__mouseOver){this.__mouseOver=!0;var e=a.copy({},t);e.type="mouseover",this.fire(e)}}else"mouseout"==t.type&&(this.__mouseOver=!1);var i=this.parent;t._stopped||t._stopPropagationed||!i||("mouseout"==t.type||"touchout"==t.type?i.hitTestPoint(t.stageX,t.stageY,!0)||i._fireMouseEvent(t):i._fireMouseEvent(t))},onUpdate:null,render:function(t,e){t.draw(this)},toString:function(){return e.viewToString(this)}})}();return o},{requires:["hilo/core/Hilo","hilo/core/Class","hilo/event/EventMixin","hilo/geom/Matrix","hilo/util/util"]}),KISSY.add("hilo/view/CacheMixin",function(t,e,i){var r,n,a={_cacheDirty:!0,cache:function(t){(t||this._cacheDirty||!this.drawable)&&this.updateCache()},updateCache:function(){i.supportCanvas&&(r||(r=document.createElement("canvas"),n=r.getContext("2d")),r.width=this.width,r.height=this.height,this._draw(n),this.drawable=this.drawable||new e,this.drawable.init({image:r.toDataURL()}),this._cacheDirty=!1)},setCacheDirty:function(t){this._cacheDirty=t}};return a},{requires:["hilo/view/Drawable","hilo/util/browser"]}),KISSY.add("hilo/view/Container",function(t,e,i,r){var n=i.create({Extends:r,constructor:function(t){t=t||{},this.id=this.id||t.id||e.getUid("Container"),n.superclass.constructor.call(this,t),this.children?this._updateChildren():this.children=[]},children:null,pointerChildren:!0,clipChildren:!1,getNumChildren:function(){return this.children.length},addChildAt:function(t,e){var i=this.children,r=i.length,n=t.parent;e=e<0?0:e>r?r:e;var a=this.getChildIndex(t);if(a==e)return this;if(a>=0?(i.splice(a,1),e=e==r?r-1:e):n&&n.removeChild(t),i.splice(e,0,t),a<0)this._updateChildren(e);else{var o=a=e.length)return null;var i=e[t];if(i){if(!i.__renderer)for(var r=i;r=r.parent;){if(r.renderer){i.__renderer=r.renderer;break}if(r.__renderer){i.__renderer=r.__renderer;break}}i.__renderer&&i.__renderer.remove(i),i.parent=null,i.depth=-1}return e.splice(t,1),this._updateChildren(t),i},removeChild:function(t){return this.removeChildAt(this.getChildIndex(t))},removeChildById:function(t){for(var e,i=this.children,r=0,n=i.length;r=e.length?null:e[t]},getChildById:function(t){for(var e,i=this.children,r=0,n=i.length;r=0&&r!=e){var n=i.length;e=e<0?0:e>=n?n-1:e,i.splice(r,1),i.splice(e,0,t),this._updateChildren()}return this},swapChildren:function(t,e){var i=this.children,r=this.getChildIndex(t),n=this.getChildIndex(e);t.depth=n,i[n]=t,e.depth=r,i[r]=e},swapChildrenAt:function(t,e){var i=this.children,r=this.getChildAt(t),n=this.getChildAt(e);r.depth=e,i[e]=r,n.depth=t,i[t]=n},sortChildren:function(t){var e=t,i=this.children;if("string"==typeof e){var r=e;e=function(t,e){return e[r]-t[r]}}i.sort(e),this._updateChildren()},_updateChildren:function(t,e){var i,r=this.children;t=t||0,e=e||r.length;for(var n=t;n=0;l--)if(a=h[l],!(!a||!a.visible||a.alpha<=0||n&&!a.pointerEnabled))if(a.children&&a.children.length&&(!n||a.pointerChildren)&&(o=a.getViewAtPoint(t,e,i,r,n)),o){if(!r)return o;o.length&&(s=s.concat(o))}else if(a.hitTestPoint(t,e,i)){if(!r)return a;s.push(a)}return r&&s.length?s:null},render:function(t,e){n.superclass.render.call(this,t,e);var i,r,a,o=this.children.slice(0);for(i=0,r=o.length;ir?r:e,i[e]=t,t.name&&(this._frameNames[t.name]=t),(0!=e||this.width)&&this.height||(this.width=t.rect[2],this.height=t.rect[3]),this},getFrame:function(t){if("number"==typeof t){var e=this._frames;return t<0||t>=e.length?null:e[t]}return this._frameNames[t]},getFrameIndex:function(t){var e=this._frames,i=e.length,r=-1;if("number"==typeof t)r=t;else{var n="string"==typeof t?this._frameNames[t]:t;if(n)for(var a=0;a=i?i-1:r,this.paused=e,this._firstRender=!0,this},_render:function(t,e){var i,r=this.currentFrame;if(this._firstRender?(i=r,this._firstRender=!1):i=this._nextFrame(e),i!=r){this.currentFrame=i;var n=this._frames[i].callback;n&&n.call(this)}this.onEnterFrame&&this.onEnterFrame(i),this.drawable.init(this._frames[i]),a.superclass._render.call(this,t,e)},_nextFrame:function(t){var e=this._frames,i=e.length,r=this.currentFrame,n=e[r],a=n.duration||this.interval,o=this._frameElapsed,s=0!=r||this.drawable?o+(this.timeBased?t:1):0;return o=this._frameElapsed=s=i-1)&&this.stop(),this.paused||0!=o||(null!=n.next?r=this.getFrameIndex(n.next):r>=i-1?r=0:this.drawable&&r++),r},setFrameCallback:function(t,e){return t=this.getFrame(t),t&&(t.callback=e),this},onEnterFrame:null});return a},{requires:["hilo/core/Hilo","hilo/core/Class","hilo/view/View","hilo/view/Drawable"]}),KISSY.add("hilo/view/DOMElement",function(t,e,i,r,n){var a=i.create({Extends:r,constructor:function(t){t=t||{},this.id=this.id||t.id||e.getUid("DOMElement"),a.superclass.constructor.call(this,t),this.drawable=new n;var i=this.drawable.domElement=t.element||e.createElement("div");i.id=this.id,this.pointerEnabled&&!i.style.pointerEvents&&(i.style.pointerEvents="visible")},_render:function(t,e){this.onUpdate&&this.onUpdate(e)===!1||(t.transform(this),this.visible&&this.alpha>0&&this.render(t,e))},render:function(t,i){if("dom"!==t.renderType){var r=t.canvas,n=this.parent,a=t._domElementContainer;t._domElementContainer||(a=t._domElementContainer=e.createElement("div",{style:{position:"absolute",transform:"scale3d("+n.scaleX+","+n.scaleY+", 1)",transformOrigin:"0 0",zIndex:"1"}}),r.parentNode.insertBefore(t._domElementContainer,r.nextSibling));var o,s=this.drawable.domElement,h=this.depth,l=a.childNodes[0];if(s.parentNode)return;for(;l&&3!=l.nodeType&&(o=parseInt(l.style.zIndex)||0,!(o<=0||o>h));)l=l.nextSibling;a.insertBefore(this.drawable.domElement,l)}else t.draw(this)}});return a},{requires:["hilo/core/Hilo","hilo/core/Class","hilo/view/View","hilo/view/Drawable"]}),KISSY.add("hilo/view/Graphics",function(t,e,i,r,n){var a=function(){var t=document.createElement("canvas"),o=t.getContext&&t.getContext("2d");return i.create({Extends:r,Mixes:n,constructor:function(t){t=t||{},this.id=this.id||t.id||e.getUid("Graphics"),a.superclass.constructor.call(this,t),this._actions=[]},lineWidth:1,lineAlpha:1,lineCap:null,lineJoin:null,miterLimit:10,hasStroke:!1,strokeStyle:"0",hasFill:!1,fillStyle:"0",fillAlpha:0,lineStyle:function(t,e,i,r,n,a){var o=this,s=o._addAction;return s.call(o,["lineWidth",o.lineWidth=t||1]),s.call(o,["strokeStyle",o.strokeStyle=e||"0"]),s.call(o,["lineAlpha",o.lineAlpha=i||1]),void 0!=r&&s.call(o,["lineCap",o.lineCap=r]),void 0!=n&&s.call(o,["lineJoin",o.lineJoin=n]),void 0!=a&&s.call(o,["miterLimit",o.miterLimit=a]),o.hasStroke=!0,o},setLineDash:function(t){return this._addAction(["setLineDash",t])},beginFill:function(t,e){var i=this,r=i._addAction;return r.call(i,["fillStyle",i.fillStyle=t]),r.call(i,["fillAlpha",i.fillAlpha=e||1]),i.hasFill=!0,i},endFill:function(){var t=this,e=t._addAction;return t.hasStroke&&e.call(t,["stroke"]),t.hasFill&&e.call(t,["fill"]),t.setCacheDirty(!0),t},beginLinearGradientFill:function(t,e,i,r,n,a){for(var s=this,h=o.createLinearGradient(t,e,i,r),l=0,c=n.length;l1?a.slice(1):null;"function"==typeof t[o]?t[o].apply(t,s):t[o]=a[1]}},render:function(t,e){var i=this;"canvas"===t.renderType?i._draw(t.context):(i.cache(),t.draw(i))},clear:function(){var t=this;return t._actions.length=0,t.lineWidth=1,t.lineAlpha=1,t.lineCap=null,t.lineJoin=null,t.miterLimit=10,t.hasStroke=!1,t.strokeStyle="0",t.hasFill=!1,t.fillStyle="0",t.fillAlpha=1,t.setCacheDirty(!0),t},_addAction:function(t){var e=this;return e._actions.push(t),e}})}();return a},{requires:["hilo/core/Hilo","hilo/core/Class","hilo/view/View","hilo/view/CacheMixin"]}),KISSY.add("hilo/view/Text",function(t,e,i,r,n){var a=e.create({Extends:r,Mixes:n,constructor:function(t){t=t||{},this.id=this.id||t.id||i.getUid("Text"),a.superclass.constructor.call(this,t),t.font||(this.font="12px arial"),this._fontHeight=a.measureFontHeight(this.font)},text:"",color:"#000",textAlign:null,textVAlign:null,outline:!1,lineSpacing:0,maxWidth:200,font:null,textWidth:0,textHeight:0,setFont:function(t){var e=this;return e.font!==t&&(e.font=t,e._fontHeight=a.measureFontHeight(t)),e},render:function(t,e){var i=this;if("canvas"===t.renderType)this.drawable?t.draw(i):i._draw(t.context);else if("dom"===t.renderType){var r=i.drawable,n=r.domElement,a=n.style;a.font=i.font,a.textAlign=i.textAlign,a.color=i.color,a.width=i.width+"px",a.height=i.height+"px",a.lineHeight=i._fontHeight+i.lineSpacing+"px",n.innerHTML=i.text,t.draw(this)}else i.cache(),t.draw(i)},_draw:function(t){var e=this,i=e.text.toString();if(i){t.font=e.font,t.textAlign=e.textAlign,t.textBaseline="top";var r,n,a,o,s,h=i.split(/\r\n|\r|\n|/),l=0,c=0,u=e._fontHeight+e.lineSpacing,d=[];for(r=0,o=h.length;re.maxWidth?(d.push({text:m,y:c}),l>1;break;case"bottom":_=e.height-e.textHeight}var x=e.background;for(x&&(t.fillStyle=x,t.fillRect(0,0,e.width,e.height)),e.outline?t.strokeStyle=e.color:t.fillStyle=e.color,r=0;r>1;break;case"right":case"end":n=a}r.outline?t.strokeText(e,n,i):t.fillText(e,n,i)},Statics:{measureFontHeight:function(t){var e,r=document.documentElement,n=i.createElement("div",{style:{font:t,position:"absolute"},innerHTML:"M"});return r.appendChild(n),e=n.offsetHeight,r.removeChild(n),e}}});return a},{requires:["hilo/core/Class","hilo/core/Hilo","hilo/view/View","hilo/view/CacheMixin"]}),KISSY.add("hilo/view/BitmapText",function(t,e,i,r,n){var a=e.create({Extends:r,constructor:function(t){t=t||{},this.id=this.id||t.id||i.getUid("BitmapText"),a.superclass.constructor.call(this,t);var e=t.text+"";e&&(this.text="",this.setText(e)),this.pointerChildren=!1},glyphs:null,letterSpacing:0,text:"",textAlign:"left",setText:function(t){var e=this,i=t.toString(),r=i.length;if(e.text!=i){e.text=i;var n,a,o,s,h=0,l=0,c=0;for(n=0;n0?e.letterSpacing:0),e.children[n]?(s=e.children[n],s.setImage(o.image,o.rect)):(s=e._createBitmap(o),e.addChild(s)),s.x=c,h=c+o.rect[2],l=Math.max(l,o.rect[3]));for(n=e.children.length-1;n>=r;n--)e._releaseBitmap(e.children[n]),e.children[n].removeFromParent();return e.width=h,e.height=l,this.setTextAlign(),e}},_createBitmap:function(t){var e;return a._pool.length?(e=a._pool.pop(),e.setImage(t.image,t.rect)):e=new n({image:t.image,rect:t.rect}),e},_releaseBitmap:function(t){a._pool.push(t)},setTextAlign:function(t){switch(this.textAlign=t||this.textAlign,this.textAlign){case"center":this.pivotX=.5*this.width;break;case"right":this.pivotX=this.width;break;case"left":default:this.pivotX=0}return this},hasGlyphs:function(t){var e=this.glyphs;if(!e)return!1;t=t.toString();var i,r=t.length;for(i=0;i=this._targetFPS?(this._measuredFPS=1e3/(this._tickTime/this._tickCount)+.5>>0,this._tickCount=0,this._tickTime=0):this._tickTime+=t-this._lastTime,this._lastTime=t;for(var r=i.slice(0),n=0,a=r.length;n=0&&e.splice(i,1)},nextTick:function(t){var e=this,i={tick:function(r){e.removeTick(i),t()}};return e.addTick(i),i},timeout:function(t,e){var i=this,r=(new Date).getTime()+e,n={tick:function(){var e=(new Date).getTime(),a=e-r;a>=0&&(i.removeTick(n),t())}};return i.addTick(n),n},interval:function(t,e){var i=this,r=(new Date).getTime()+e,n={tick:function(){var i=(new Date).getTime(),n=i-r;n>=0&&(n=r)return-1;for(e<0&&(e=r+e),i=e;i=1?1:s;var l=n.ease?n.ease(s):s;n.reverse&&n.isStart&&(n._reverseFlag<0&&(s=1-s,l=1-l),s<1e-7&&(n.repeat>0&&n._repeatCount++>=n.repeat||0==n.repeat&&!n.loop?h=!0:(n._startTime=t(),n._pausedTime=0,n._reverseFlag*=-1))),n.isStart||(n.setProps(n._fromProps,n._toProps),n.isStart=!0,n.onStart&&n.onStart.call(n,n)),n.time=a,n._render(l),(o=n.onUpdate)&&o.call(n,s,n),s>=1&&(n.reverse?(n._startTime=t(),n._pausedTime=0,n._reverseFlag*=-1):n.loop||n.repeat>0&&n._repeatCount++0&&u<=e?(c._render(s),c.time=a,i.add(c)):n.isComplete&&(u<0||u>e)&&c.start()}return n.isComplete?((o=n.onComplete)&&o.call(n,n),!0):void 0}}},Statics:{_tweens:[],tick:function(){var e,r,n=i._tweens,a=n.length;for(r=0;r-1&&n.splice(e,1);else for(e=0;e=i)return void t.fire("complete");if(t._currentIndexe.z})},tick:function(){this.sortZ()}});return o}();return r},{requires:["hilo/core/Class","hilo/util/util"]}),KISSY.add("hilo/game/ParticleSystem",function(t,e,i,r,n,a,o){var s=function(){function t(t,e){return e?t+2*(Math.random()-.5)*e:t}for(var s=["x","y","vx","vy","ax","ay","rotation","rotationV","scale","scaleV","alpha","alphaV","life"],h=[],l=0,c=s.length;l=this._emitTime&&(this._currentRunTime=0,this._emitTime=t(this.emitTime,this.emitTimeVar),this._emit()),this._totalRunTime>=this.totalTime&&this.stop())},_emit:function(){for(var e=t(this.emitNum,this.emitNumVar)>>0,i=0;i=0;e--)this.children[e].destroy()}}),v=i.create({Extends:r,constructor:function(t){this.id=this.id||t.id||e.getUid("Particle"),v.superclass.constructor.call(this,t),this.init(t)},onUpdate:function(t){if(t*=.001,this._died)return!1;var e=this.ax+this.system.gx,i=this.ay+this.system.gy;return this.vx+=e*t,this.vy+=i*t,this.x+=this.vx*t,this.y+=this.vy*t,this.rotation+=this.rotationV,this._time>.1&&(this.alpha+=this.alphaV),this.scale+=this.scaleV,this.scaleX=this.scaleY=this.scale,this._time+=t,this._time>=this.life||this.alpha<=0?(this.destroy(),!1):void 0},setImage:function(t,e){this.drawable=this.drawable||new a,e=e||[0,0,t.width,t.height],this.width=e[2],this.height=e[3],this.drawable.rect=e,this.drawable.image=t},destroy:function(){this._died=!0,this.alpha=0,this.removeFromParent(),f.push(this)},init:function(e){this.system=e.system,this._died=!1,this._time=0,this.alpha=1;for(var i=0,r=h.length;i>0]),this.setImage(e.image,o),void 0!==e.pivotX&&(this.pivotX=e.pivotX*o[2]),void 0!==e.pivotY&&(this.pivotY=e.pivotY*o[3])}},Statics:{create:function(t){if(f.length>0){var e=f.pop();return e.init(t),e}return new v(t)}}});return p}();return s},{requires:["hilo/core/Hilo","hilo/core/Class","hilo/view/View","hilo/view/Container","hilo/view/Drawable","hilo/util/util"]}); \ No newline at end of file +KISSY.add("hilo/util/browser",function(t){var e=function(){var t=navigator.userAgent,e=document,i=window,r=e.documentElement,n={iphone:/iphone/i.test(t),ipad:/ipad/i.test(t),ipod:/ipod/i.test(t),ios:/iphone|ipad|ipod/i.test(t),android:/android/i.test(t),webkit:/webkit/i.test(t),chrome:/chrome/i.test(t),safari:/safari/i.test(t),firefox:/firefox/i.test(t),ie:/msie/i.test(t),opera:/opera/i.test(t),supportTouch:"ontouchstart"in i,supportCanvas:null!=e.createElement("canvas").getContext,supportStorage:!1,supportOrientation:"orientation"in i||"orientation"in i.screen,supportDeviceMotion:"ondevicemotion"in i};try{var a="hilo";localStorage.setItem(a,a),localStorage.removeItem(a),n.supportStorage=!0}catch(o){}var s=n.jsVendor=n.webkit?"webkit":n.firefox?"webkit":n.opera?"o":n.ie?"ms":"",h=n.cssVendor="-"+s+"-",l=e.createElement("div"),c=l.style,u=void 0!=c[s+"Transform"],d=void 0!=c[s+"Perspective"];d&&(l.id="test3d",c=e.createElement("style"),c.textContent="@media ("+h+"transform-3d){#test3d{height:3px}}",e.head.appendChild(c),r.appendChild(l),d=3==l.offsetHeight,e.head.removeChild(c),r.removeChild(l)),n.supportTransform=u,n.supportTransform3D=d;var f=n.supportTouch,p=f?"touchstart":"mousedown",v=f?"touchmove":"mousemove",m=f?"touchend":"mouseup";return n.POINTER_START=p,n.POINTER_MOVE=v,n.POINTER_END=m,n}();return e}),KISSY.add("hilo/util/util",function(t){var e={copy:function(t,e,i){for(var r in e)i&&!t.hasOwnProperty(r)&&void 0===t[r]||(t[r]=e[r]);return t}};return e}),KISSY.add("hilo/core/Hilo",function(t,e,i){var r=window,n=document,a=n.documentElement,o=0,s={},h={version:"1.6.0",getUid:function(t){var e=++o;if(t){var i=t.charCodeAt(t.length-1);return i>=48&&i<=57&&(t+="_"),t+e}return e},viewToString:function(t){for(var e,i=t;i;)e=e?i.id+"."+e:i.id,i=i.parent;return e},copy:function(t,e,r){return i.copy(t,e,r),s.copy||(s.copy=!0,console.warn("Hilo.copy has been Deprecated! Use Hilo.util.copy instead.")),t},browser:e,event:{POINTER_START:e.POINTER_START,POINTER_MOVE:e.POINTER_MOVE,POINTER_END:e.POINTER_END},align:{TOP_LEFT:"TL",TOP:"T",TOP_RIGHT:"TR",LEFT:"L",CENTER:"C",RIGHT:"R",BOTTOM_LEFT:"BL",BOTTOM:"B",BOTTOM_RIGHT:"BR"},getElementRect:function(t){var e;try{e=t.getBoundingClientRect()}catch(i){e={top:t.offsetTop,left:t.offsetLeft,right:t.offsetLeft+t.offsetWidth,bottom:t.offsetTop+t.offsetHeight}}var n=(r.pageXOffset||a.scrollLeft)-(a.clientLeft||0)||0,o=(r.pageYOffset||a.scrollTop)-(a.clientTop||0)||0,s=r.getComputedStyle?getComputedStyle(t):t.currentStyle,h=parseInt,l=h(s.paddingLeft)+h(s.borderLeftWidth)||0,c=h(s.paddingTop)+h(s.borderTopWidth)||0,u=h(s.paddingRight)+h(s.borderRightWidth)||0,d=h(s.paddingBottom)+h(s.borderBottomWidth)||0,f=e.top||0,p=e.left||0,v=e.right||0,m=e.bottom||0;return{left:p+n+l,top:f+o+c,width:v-u-p-l,height:m-d-f-c}},createElement:function(t,e){var i,r,a,o=n.createElement(t);for(i in e)if(r=e[i],"style"===i)for(a in r)o.style[a]=r[a];else o[i]=r;return o},getElement:function(t){return n.getElementById(t)},setElementStyleByView:function(t){var e=t.drawable,i=e.domElement.style,r=t._stateCache||(t._stateCache={}),n=h.browser.jsVendor,a="px",o=!1;if(this.cacheStateIfChanged(t,["visible"],r)&&(i.display=t.visible?"":"none"),this.cacheStateIfChanged(t,["alpha"],r)&&(i.opacity=t.alpha),t.visible&&!(t.alpha<=0)){if(this.cacheStateIfChanged(t,["width"],r)&&(i.width=t.width+a),this.cacheStateIfChanged(t,["height"],r)&&(i.height=t.height+a),this.cacheStateIfChanged(t,["depth"],r)&&(i.zIndex=t.depth+1),t.transform){var s=t.transform;(o=this.cacheStateIfChanged(t,["pivotX","pivotY"],r))&&(i[n+"TransformOrigin"]="0 0"),i[n+"Transform"]="matrix3d("+s.a+", "+s.b+", 0, 0, "+s.c+", "+s.d+", 0, 0, 0, 0, 1, 0, "+s.tx+", "+s.ty+", 0, 1)"}else(o=this.cacheStateIfChanged(t,["pivotX","pivotY"],r))&&(i[n+"TransformOrigin"]=t.pivotX+a+" "+t.pivotY+a),(this.cacheStateIfChanged(t,["x","y","rotation","scaleX","scaleY"],r)||o)&&(i[n+"Transform"]=this.getTransformCSS(t));this.cacheStateIfChanged(t,["background"],r)&&(i.backgroundColor=t.background),i.pointerEvents||(i.pointerEvents="none");var l=e.image;if(l){var c=l.src;c!==r.image&&(r.image=c,i.backgroundImage="url("+c+")");var u=e.rect;if(u){var d=u[0],f=u[1];d!==r.sx&&(r.sx=d,i.backgroundPositionX=-d+a),f!==r.sy&&(r.sy=f,i.backgroundPositionY=-f+a)}}var p=t.mask;if(p){var v=p.drawable.domElement.style.backgroundImage;v!==r.maskImage&&(r.maskImage=v,i[n+"MaskImage"]=v,i[n+"MaskRepeat"]="no-repeat");var m=p.x,g=p.y;m===r.maskX&&g===r.maskY||(r.maskX=m,r.maskY=g,i[n+"MaskPosition"]=m+a+" "+g+a)}}},cacheStateIfChanged:function(t,e,i){var r,n,a,o,s=!1;for(r=0,n=e.length;r=6?(e=s[0],i=s[1],r=s[2],n=s[3],a=s[4],o=s[5]):(e=t.a,i=t.b,r=t.c,n=t.d,a=t.tx,o=t.ty),this.a=h*e+l*r,this.b=h*i+l*n,this.c=c*e+u*r,this.d=c*i+u*n,this.tx=d*e+f*r+a,this.ty=d*i+f*n+o,this},rotate:function(t){var e=Math.sin(t),i=Math.cos(t),r=this.a,n=this.b,a=this.c,o=this.d,s=this.tx,h=this.ty;return this.a=r*i-n*e,this.b=r*e+n*i,this.c=a*i-o*e,this.d=a*e+o*i,this.tx=s*i-h*e,this.ty=s*e+h*i,this},scale:function(t,e){return this.a*=t,this.d*=e,this.c*=t,this.b*=e,this.tx*=t,this.ty*=e,this},translate:function(t,e){return this.tx+=t,this.ty+=e,this},identity:function(){return this.a=this.d=1,this.b=this.c=this.tx=this.ty=0,this},invert:function(){var t=this.a,e=this.b,i=this.c,r=this.d,n=this.tx,a=t*r-e*i;return this.a=r/a,this.b=-e/a,this.c=-i/a,this.d=t/a,this.tx=(i*this.ty-r*n)/a,this.ty=-(t*this.ty-e*n)/a,this},transformPoint:function(t,e,i){var r=t.x*this.a+t.y*this.c+this.tx,n=t.x*this.b+t.y*this.d+this.ty;return e&&(r=r+.5>>0,n=n+.5>>0),i?{x:r,y:n}:(t.x=r,t.y=n,t)}});return i},{requires:["hilo/core/Class"]}),KISSY.add("hilo/event/EventMixin",function(t,e){var i={_listeners:null,on:function(t,e,i){for(var r=this._listeners=this._listeners||{},n=r[t]=r[t]||[],a=0,o=n.length;a-1&&o.splice(c,1)}}return 0==o.length&&delete a[n],!0}return!1}},r=e.create({constructor:function(t,e,i){this.type=t,this.target=e,this.detail=i,this.timeStamp=+new Date},type:null,target:null,detail:null,timeStamp:0,stopImmediatePropagation:function(){this._stopped=!0}}),n=window.Event;if(n){var a=n.prototype,o=a.stopImmediatePropagation;a.stopImmediatePropagation=function(){o&&o.call(this),this._stopped=!0}}return i},{requires:["hilo/core/Class"]}),KISSY.add("hilo/view/Drawable",function(t,e,i){var r=e.create({constructor:function(t){this.init(t)},image:null,rect:null,init:function(t){var e=this,n=e.image;r.isDrawable(t)?e.image=t:i.copy(e,t,!0);var a=e.image;if("string"==typeof a){if(!n||a!==n.getAttribute("src")){e.image=null;var o=new Image;return t.crossOrigin&&(o.crossOrigin="Anonymous"),o.onload=function(){o.onload=null,e.init(o)},void(o.src=a)}a=e.image=n}a&&!e.rect&&(e.rect=[0,0,a.width,a.height])},Statics:{isDrawable:function(t){if(!t||!t.tagName)return!1;var e=t.tagName.toLowerCase();return"img"===e||"canvas"===e||"video"===e}}});return r},{requires:["hilo/core/Class","hilo/util/util"]}),KISSY.add("hilo/renderer/Renderer",function(t,e,i){var r=e.create({constructor:function(t){t=t||{},i.copy(this,t,!0)},renderType:null,canvas:null,stage:null,blendMode:"source-over",startDraw:function(t){},draw:function(t){},endDraw:function(t){},transform:function(){},hide:function(){},remove:function(t){},clear:function(t,e,i,r){},resize:function(t,e){}});return r},{requires:["hilo/core/Class","hilo/util/util"]}),KISSY.add("hilo/renderer/CanvasRenderer",function(t,e,i,r){var n=e.create({Extends:r,constructor:function(t){n.superclass.constructor.call(this,t),this.context=this.canvas.getContext("2d")},renderType:"canvas",context:null,startDraw:function(t){return!!(t.visible&&t.alpha>0)&&(t===this.stage&&this.context.clearRect(0,0,t.width,t.height),t.blendMode!==this.blendMode&&(this.context.globalCompositeOperation=this.blendMode=t.blendMode),this.context.save(),!0)},draw:function(t){var e=this.context,i=t.width,r=t.height,n=t.background;n&&(e.fillStyle=n,e.fillRect(0,0,i,r));var a=t.drawable,o=a&&a.image;if(o){var s=a.rect,h=s[2],l=s[3],c=s[4],u=s[5];if(!h||!l)return;i||r||(i=t.width=h,r=t.height=l),(c||u)&&e.translate(c-.5*h,u-.5*l),e.drawImage(o,s[0],s[1],h,l,0,0,i,r)}},endDraw:function(t){this.context.restore()},transform:function(t){var e=t.drawable;if(e&&e.domElement)return void i.setElementStyleByView(t);var r=this.context,n=t.scaleX,a=t.scaleY;if(t===this.stage){var o=this.canvas.style,s=t._scaleX,h=t._scaleY,l=!1;(!s&&1!=n||s&&s!=n)&&(t._scaleX=n,o.width=n*t.width+"px",l=!0),(!h&&1!=a||h&&h!=a)&&(t._scaleY=a,o.height=a*t.height+"px",l=!0),l&&t.updateViewport()}else{var c=t.x,u=t.y,d=t.pivotX,f=t.pivotY,p=t.rotation%360,v=t.transform,m=t.mask;m&&(m._render(this),r.clip());var g=t.align;if(g){var _=t.getAlignPosition();c=_.x,u=_.y}v?r.transform(v.a,v.b,v.c,v.d,v.tx,v.ty):(0==c&&0==u||r.translate(c,u),0!=p&&r.rotate(p*Math.PI/180),1==n&&1==a||r.scale(n,a),0==d&&0==f||r.translate(-d,-f))}t.alpha>0&&(r.globalAlpha*=t.alpha)},remove:function(t){var e=t.drawable,i=e&&e.domElement;if(i){var r=i.parentNode;r&&r.removeChild(i)}},clear:function(t,e,i,r){this.context.clearRect(t,e,i,r)},resize:function(t,e){var i=this.canvas,r=this.stage,n=i.style;i.width=t,i.height=e,n.width=r.width*r.scaleX+"px",n.height=r.height*r.scaleY+"px"}});return n},{requires:["hilo/core/Class","hilo/core/Hilo","hilo/renderer/Renderer"]}),KISSY.add("hilo/renderer/DOMRenderer",function(t,e,i,r,n){var a=function(){function t(t,e){var r=t.tagName||"div",n=e.image,a=t.width||n&&n.width,o=t.height||n&&n.height,s=i.createElement(r),h=s.style;if(t.id&&(s.id=t.id),h.position="absolute",h.left=(t.left||0)+"px",h.top=(t.top||0)+"px",h.width=a+"px",h.height=o+"px","canvas"==r){if(s.width=a,s.height=o,n){var l=s.getContext("2d"),c=e.rect||[0,0,a,o];l.drawImage(n,c[0],c[1],c[2],c[3],t.x||0,t.y||0,t.width||c[2],t.height||c[3])}}else if(h.opacity=void 0!=t.alpha?t.alpha:1,(t===this.stage||t.clipChildren)&&(h.overflow="hidden"),n&&n.src){h.backgroundImage="url("+n.src+")";var u=t.rectX||0,d=t.rectY||0;h.backgroundPosition=-u+"px "+-d+"px"}return s}return e.create({Extends:r,constructor:function(t){a.superclass.constructor.call(this,t)},renderType:"dom",startDraw:function(e){var i=e.drawable=e.drawable||new n;return i.domElement=i.domElement||t(e,i),!0},draw:function(t){var e=t.parent,i=t.drawable.domElement,r=i.parentNode;if(e){var n=e.drawable.domElement;if(n!=r&&n.appendChild(i),!t.width&&!t.height){var a=t.drawable.rect;a&&(a[2]||a[3])&&(t.width=a[2],t.height=a[3])}}else t!==this.stage||r||(i.style.overflow="hidden",this.canvas.appendChild(i))},transform:function(t){if(i.setElementStyleByView(t),t===this.stage){var e=this.canvas.style,r=t._scaleX,n=t._scaleY,a=t.scaleX,o=t.scaleY;(!r&&1!=a||r&&r!=a)&&(t._scaleX=a,e.width=a*t.width+"px"),(!n&&1!=o||n&&n!=o)&&(t._scaleY=o,e.height=o*t.height+"px")}},remove:function(t){var e=t.drawable,i=e&&e.domElement;if(i){var r=i.parentNode;r&&r.removeChild(i)}},hide:function(t){var e=t.drawable&&t.drawable.domElement;e&&(e.style.display="none")},resize:function(t,e){var i=this.canvas.style;i.width=t+"px",i.height=e+"px","absolute"!=i.position&&(i.position="relative")}})}();return a},{requires:["hilo/core/Class","hilo/core/Hilo","hilo/renderer/Renderer","hilo/view/Drawable"]}),KISSY.add("hilo/renderer/WebGLRenderer",function(t,e,i,r,n){var a=Math.PI/180,o=e.create({Extends:r,Statics:{MAX_BATCH_NUM:2e3,ATTRIBUTE_NUM:5,isSupport:function(){if(void 0==this._isSupported){var t=document.createElement("canvas");t.getContext&&(t.getContext("webgl")||t.getContext("experimental-webgl"))?this._isSupported=!0:this._isSupported=!1}return this._isSupported},contextOptions:null},renderType:"webgl",gl:null,_isContextLost:!1,_cacheTexture:{},constructor:function(t){o.superclass.constructor.call(this,t);var e=this,i=o.contextOptions||{};this.gl=this.canvas.getContext("webgl",i)||this.canvas.getContext("experimental-webgl",i),this.maxBatchNum=o.MAX_BATCH_NUM,this.positionStride=4*o.ATTRIBUTE_NUM;var r=this.maxBatchNum*o.ATTRIBUTE_NUM*4,n=6*this.maxBatchNum;this.arrayBuffer=new ArrayBuffer(4*r),this.float32Array=new Float32Array(this.arrayBuffer),this.uint32Array=new Uint32Array(this.arrayBuffer),this.indexs=new Uint16Array(n);for(var a=0,s=0;a0)&&(t===this.stage&&this.clear(),!0)},draw:function(t){var e=t.width,i=t.height,r=(t.background,t.drawable),n=r&&r.image;if(n){var a=r.rect,o=a[2],s=a[3];e||i||(e=t.width=o,i=t.height=s),this.batchIndex>=this.maxBatchNum&&this._renderBatches();var h=this._createVertexs(n,a[0],a[1],o,s,0,0,e,i),l=this.batchIndex*this.positionStride,c=this.float32Array,u=this.uint32Array,d=(t.tint>>16)+(65280&t.tint)+((255&t.tint)<<16)+(255*t.__webglRenderAlpha<<24);c[l+0]=h[0],c[l+1]=h[1],c[l+2]=h[2],c[l+3]=h[3],u[l+4]=d,c[l+5]=h[4],c[l+6]=h[5],c[l+7]=h[6],c[l+8]=h[7],u[l+9]=d,c[l+10]=h[8],c[l+11]=h[9],c[l+12]=h[10],c[l+13]=h[11],u[l+14]=d,c[l+15]=h[12],c[l+16]=h[13],c[l+17]=h[14],c[l+18]=h[15],u[l+19]=d;for(var f=t.__webglWorldMatrix,p=0;p<4;p++){var v=c[l+5*p],m=c[l+5*p+1];c[l+5*p]=f.a*v+f.c*m+f.tx,c[l+5*p+1]=f.b*v+f.d*m+f.ty}t.__textureImage=n,this.sprites[this.batchIndex++]=t}},endDraw:function(t){t===this.stage&&this._renderBatches()},transform:function(t){var e=t.drawable;if(e&&e.domElement)return void i.setElementStyleByView(t);var r=t.scaleX,a=t.scaleY;if(t===this.stage){var o=this.canvas.style,s=t._scaleX,h=t._scaleY,l=!1;(!s&&1!=r||s&&s!=r)&&(t._scaleX=r,o.width=r*t.width+"px",l=!0),(!h&&1!=a||h&&h!=a)&&(t._scaleY=a,o.height=a*t.height+"px",l=!0),l&&t.updateViewport(),t.__webglWorldMatrix=t.__webglWorldMatrix||new n(1,0,0,1,0,0)}else t.parent&&(t.__webglWorldMatrix=t.__webglWorldMatrix||new n(1,0,0,1,0,0),this._setConcatenatedMatrix(t,t.parent));t.alpha>0&&(t.parent&&t.parent.__webglRenderAlpha?t.__webglRenderAlpha=t.alpha*t.parent.__webglRenderAlpha:t.__webglRenderAlpha=t.alpha)},remove:function(t){var e=t.drawable,i=e&&e.domElement;if(i){var r=i.parentNode;r&&r.removeChild(i)}},clear:function(t,e,i,r){this.gl.clear(this.gl.COLOR_BUFFER_BIT)},resize:function(t,e){if(this.width!==t||this.height!==e){var i=this.canvas,r=this.stage,n=i.style;this.width=i.width=t,this.height=i.height=e,n.width=r.width*r.scaleX+"px",n.height=r.height*r.scaleY+"px",this.gl.viewport(0,0,t,e),this.canvasHalfWidth=.5*t,this.canvasHalfHeight=.5*e,this._uploadProjectionTransform(!0)}},_renderBatches:function(){var t=this.gl;t.bufferSubData(t.ARRAY_BUFFER,0,this.uint32Array.subarray(0,this.batchIndex*this.positionStride));for(var e=0,i=0,r=null,n=0;n0&&(i.bindTexture(i.TEXTURE_2D,this._getTexture(this.sprites[t])),i.drawElements(i.TRIANGLES,6*r,i.UNSIGNED_SHORT,6*t*2))},_uploadProjectionTransform:function(t){this._projectionTransformElements&&!t||(this._projectionTransformElements=new Float32Array([1/this.canvasHalfWidth,0,0,0,-1/this.canvasHalfHeight,0,-1,1,1])),this.gl.uniformMatrix3fv(this.u_projectionTransform,!1,this._projectionTransformElements)},_initShaders:function(){var t=" attribute vec2 a_position;\n attribute vec2 a_TexCoord;\n attribute vec4 a_tint;\n uniform mat3 u_projectionTransform;\n varying vec2 v_TexCoord;\n varying vec4 v_tint;\n void main(){\n gl_Position = vec4((u_projectionTransform * vec3(a_position, 1.0)).xy, 1.0, 1.0);\n v_TexCoord = a_TexCoord;\n v_tint = vec4(a_tint.rgb * a_tint.a, a_tint.a);\n }\n ",e="\n precision mediump float;\n uniform sampler2D u_Sampler;\n varying vec2 v_TexCoord;\n varying vec4 v_tint;\n void main(){\n gl_FragColor = texture2D(u_Sampler, v_TexCoord) * v_tint;\n }\n ";this.defaultShader=new s(this,{v:t,f:e},{attributes:["a_position","a_TexCoord","a_tint"],uniforms:["u_projectionTransform","u_Sampler"]})},_createVertexs:function(t,e,i,r,n,a,o,s,h){var l=this.__tempVertexs||[],c=t.width,u=t.height;r/=c,n/=u,e/=c,i/=u,s=s,h=h,a=a,o=o,r+e>1&&(r=1-e),n+i>1&&(n=1-i);var d=0;return l[d++]=a,l[d++]=o,l[d++]=e,l[d++]=i,l[d++]=a+s,l[d++]=o,l[d++]=e+r,l[d++]=i,l[d++]=a,l[d++]=o+h,l[d++]=e,l[d++]=i+n,l[d++]=a+s,l[d++]=o+h,l[d++]=e+r,l[d++]=i+n,l},_setConcatenatedMatrix:function(t,e){var i=t.__webglWorldMatrix,r=1,n=0,o=t.rotation%360,s=t.pivotX,h=t.pivotY,l=t.scaleX,c=t.scaleY,u=t.transform;if(u)i.copy(u);else{if(o){var d=o*a;r=Math.cos(d),n=Math.sin(d)}var f=t.getAlignPosition();i.a=r*l,i.b=n*l,i.c=-n*c,i.d=r*c,i.tx=f.x-i.a*s-i.c*h,i.ty=f.y-i.b*s-i.d*h}i.concat(e.__webglWorldMatrix)},_getTexture:function(t){var e=t.__textureImage,i=this._cacheTexture[e.src];return i||(i=this.activeShader.uploadTexture(e)),i}}),s=function(t,e,i){this.renderer=t,this.gl=t.gl,this.program=this._createProgram(this.gl,e.v,e.f),i=i||{},this.attributes=i.attributes||[],this.uniforms=i.uniforms||[]};return s.prototype={active:function(){var t=this,e=t.renderer,i=t.gl,r=t.program;r&&i&&(e.activeShader=t,i.useProgram(r),t.attributes.forEach(function(t){e[t]=i.getAttribLocation(r,t),i.enableVertexAttribArray(e[t])}),t.uniforms.forEach(function(t){e[t]=i.getUniformLocation(r,t)}),t.width===e.width&&t.height===e.height||(t.width=e.width,t.height=e.height,e._uploadProjectionTransform()))},uploadTexture:function(t){var e=this.gl,i=this.renderer,r=e.createTexture(),n=i.u_Sampler;return e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,r),e.pixelStorei(e.UNPACK_PREMULTIPLY_ALPHA_WEBGL,1),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,t),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.uniform1i(n,0),e.bindTexture(e.TEXTURE_2D,null),this.renderer._cacheTexture[t.src]=r,r},_createProgram:function(t,e,i){var r=this._createShader(t,t.VERTEX_SHADER,e),n=this._createShader(t,t.FRAGMENT_SHADER,i);if(!r||!n)return null;var a=t.createProgram();if(a){t.attachShader(a,r),t.attachShader(a,n),t.linkProgram(a),t.deleteShader(n),t.deleteShader(r);var o=t.getProgramParameter(a,t.LINK_STATUS);if(!o){var s=t.getProgramInfoLog(a);return console.log("Failed to link program: "+s),t.deleteProgram(a),null}}return a},_createShader:function(t,e,i){var r=t.createShader(e);if(r){t.shaderSource(r,i),t.compileShader(r);var n=t.getShaderParameter(r,t.COMPILE_STATUS);if(!n){var a=t.getShaderInfoLog(r);return console.log("Failed to compile shader: "+a),t.deleteShader(r),null}}return r}},o},{requires:["hilo/core/Class","hilo/core/Hilo","hilo/renderer/Renderer","hilo/geom/Matrix"]}),KISSY.add("hilo/view/View",function(t,e,i,r,n,a){var o=function(){function t(t,e,i){for(var r,n,a,o,s=0,h=!1,l=0,c=i.length;ld.x?(r=d.x,n=u.x):(r=u.x,n=d.x),t>=r&&t<=n))h=!0;else if(u.y>d.y?(a=d.y,o=u.y):(a=u.y,o=d.y),!(eo)){var f=(e-u.y)*(d.x-u.x)/(d.y-u.y)+u.x;if(f>t?s++:f==t&&(h=!0),u.x>t&&u.y==e){var p=i[(c+l-1)%c];(p.ye||p.y>e&&d.ys?s=c:cl?l=c:c=0)return!1;u>i.overlap&&(i.overlap=u,i.normal.x=p.x,i.normal.y=p.y)}return i}return i.create({Mixes:r,constructor:function(t){t=t||{},this.id=this.id||t.id||e.getUid("View"),a.copy(this,t,!0)},tint:16777215,id:null,x:0,y:0,width:0,height:0,alpha:1,rotation:0,visible:!0,pivotX:0,pivotY:0,scaleX:1,scaleY:1,pointerEnabled:!0,background:null,mask:null,align:null,drawable:null,boundsArea:null,parent:null,depth:-1,transform:null,blendMode:"source-over",getStage:function(){for(var t,e=this;t=e.parent;)e=t;return e.canvas?e:null},getScaledWidth:function(){return this.width*this.scaleX},getScaledHeight:function(){return this.height*this.scaleY},addTo:function(t,e){return"number"==typeof e?t.addChildAt(this,e):t.addChild(this),this},removeFromParent:function(){var t=this.parent;return t&&t.removeChild(this),this},getBounds:function(){for(var t,e,i,r,n,a,o,s=this.width,h=this.height,l=this.getConcatenatedMatrix(),c=this.boundsArea||[{x:0,y:0},{x:s,y:0},{x:s,y:h},{x:0,y:h}],u=[],d=0,f=c.length;de?r=e:ni?a=i:o>1,r=0;break;case"TR":i=o-n,r=0;break;case"L":i=0,r=s-a>>1;break;case"C":i=o-n>>1,r=s-a>>1;break;case"R":i=o-n,r=s-a>>1;break;case"BL":i=0,r=s-a;break;case"B":i=o-n>>1,r=s-a;break;case"BR":i=o-n,r=s-a}}return{x:i,y:r}},hitTestPoint:function(e,i,r){var n=this.getBounds(),a=e>=n.x&&e<=n.x+n.width&&i>=n.y&&i<=n.y+n.height;return a&&r&&(a=t(e,i,n)),a},hitTestObject:function(t,e){var i=this.getBounds(),r=t.getBounds(),n=i.x<=r.x+r.width&&r.x<=i.x+i.width&&i.y<=r.y+r.height&&r.y<=i.y+i.height;return n&&e&&(n=o(i,r)),!!n},_render:function(t,e){this.onUpdate&&this.onUpdate(e)===!1||!t.startDraw(this)||(t.transform(this),this.render(t,e),t.endDraw(this))},_fireMouseEvent:function(t){if(t.eventCurrentTarget=this,this.fire(t),"mousemove"==t.type){if(!this.__mouseOver){this.__mouseOver=!0;var e=a.copy({},t);e.type="mouseover",this.fire(e)}}else"mouseout"==t.type&&(this.__mouseOver=!1);var i=this.parent;t._stopped||t._stopPropagationed||!i||("mouseout"==t.type||"touchout"==t.type?i.hitTestPoint(t.stageX,t.stageY,!0)||i._fireMouseEvent(t):i._fireMouseEvent(t))},onUpdate:null,render:function(t,e){t.draw(this)},toString:function(){return e.viewToString(this)}})}();return o},{requires:["hilo/core/Hilo","hilo/core/Class","hilo/event/EventMixin","hilo/geom/Matrix","hilo/util/util"]}),KISSY.add("hilo/view/CacheMixin",function(t,e,i){var r,n,a={_cacheDirty:!0,cache:function(t){(t||this._cacheDirty||!this.drawable)&&this.updateCache()},updateCache:function(){i.supportCanvas&&(r||(r=document.createElement("canvas"),n=r.getContext("2d")),r.width=this.width,r.height=this.height,this._draw(n),this.drawable=this.drawable||new e,this.drawable.init({image:r.toDataURL()}),this._cacheDirty=!1)},setCacheDirty:function(t){this._cacheDirty=t}};return a},{requires:["hilo/view/Drawable","hilo/util/browser"]}),KISSY.add("hilo/view/Container",function(t,e,i,r){var n=i.create({Extends:r,constructor:function(t){t=t||{},this.id=this.id||t.id||e.getUid("Container"),n.superclass.constructor.call(this,t),this.children?this._updateChildren():this.children=[]},children:null,pointerChildren:!0,clipChildren:!1,getNumChildren:function(){return this.children.length},addChildAt:function(t,e){var i=this.children,r=i.length,n=t.parent;e=e<0?0:e>r?r:e;var a=this.getChildIndex(t);if(a==e)return this;if(a>=0?(i.splice(a,1),e=e==r?r-1:e):n&&n.removeChild(t),i.splice(e,0,t),a<0)this._updateChildren(e);else{var o=a=e.length)return null;var i=e[t];if(i){if(!i.__renderer)for(var r=i;r=r.parent;){if(r.renderer){i.__renderer=r.renderer;break}if(r.__renderer){i.__renderer=r.__renderer;break}}i.__renderer&&i.__renderer.remove(i),i.parent=null,i.depth=-1}return e.splice(t,1),this._updateChildren(t),i},removeChild:function(t){return this.removeChildAt(this.getChildIndex(t))},removeChildById:function(t){for(var e,i=this.children,r=0,n=i.length;r=e.length?null:e[t]},getChildById:function(t){for(var e,i=this.children,r=0,n=i.length;r=0&&r!=e){var n=i.length;e=e<0?0:e>=n?n-1:e,i.splice(r,1),i.splice(e,0,t),this._updateChildren()}return this},swapChildren:function(t,e){var i=this.children,r=this.getChildIndex(t),n=this.getChildIndex(e);t.depth=n,i[n]=t,e.depth=r,i[r]=e},swapChildrenAt:function(t,e){var i=this.children,r=this.getChildAt(t),n=this.getChildAt(e);r.depth=e,i[e]=r,n.depth=t,i[t]=n},sortChildren:function(t){var e=t,i=this.children;if("string"==typeof e){var r=e;e=function(t,e){return e[r]-t[r]}}i.sort(e),this._updateChildren()},_updateChildren:function(t,e){var i,r=this.children;t=t||0,e=e||r.length;for(var n=t;n=0;l--)if(a=h[l],!(!a||!a.visible||a.alpha<=0||n&&!a.pointerEnabled))if(a.children&&a.children.length&&(!n||a.pointerChildren)&&(o=a.getViewAtPoint(t,e,i,r,n)),o){if(!r)return o;o.length&&(s=s.concat(o))}else if(a.hitTestPoint(t,e,i)){if(!r)return a;s.push(a)}return r&&s.length?s:null},render:function(t,e){n.superclass.render.call(this,t,e);var i,r,a,o=this.children.slice(0);for(i=0,r=o.length;ir?r:e,i[e]=t,t.name&&(this._frameNames[t.name]=t),(0!=e||this.width)&&this.height||(this.width=t.rect[2],this.height=t.rect[3]),this},getFrame:function(t){if("number"==typeof t){var e=this._frames;return t<0||t>=e.length?null:e[t]}return this._frameNames[t]},getFrameIndex:function(t){var e=this._frames,i=e.length,r=-1;if("number"==typeof t)r=t;else{var n="string"==typeof t?this._frameNames[t]:t;if(n)for(var a=0;a=i?i-1:r,this.paused=e,this._firstRender=!0,this},_render:function(t,e){var i,r=this.currentFrame;if(this._firstRender?(i=r,this._firstRender=!1):i=this._nextFrame(e),i!=r){this.currentFrame=i;var n=this._frames[i].callback;n&&n.call(this)}this.onEnterFrame&&this.onEnterFrame(i),this.drawable.init(this._frames[i]),a.superclass._render.call(this,t,e)},_nextFrame:function(t){var e=this._frames,i=e.length,r=this.currentFrame,n=e[r],a=n.duration||this.interval,o=this._frameElapsed,s=0!=r||this.drawable?o+(this.timeBased?t:1):0;return o=this._frameElapsed=s=i-1)&&this.stop(),this.paused||0!=o||(null!=n.next?r=this.getFrameIndex(n.next):r>=i-1?r=0:this.drawable&&r++),r},setFrameCallback:function(t,e){return t=this.getFrame(t),t&&(t.callback=e),this},onEnterFrame:null});return a},{requires:["hilo/core/Hilo","hilo/core/Class","hilo/view/View","hilo/view/Drawable"]}),KISSY.add("hilo/view/DOMElement",function(t,e,i,r,n){var a=i.create({Extends:r,constructor:function(t){t=t||{},this.id=this.id||t.id||e.getUid("DOMElement"),a.superclass.constructor.call(this,t),this.drawable=new n;var i=this.drawable.domElement=t.element||e.createElement("div");i.id=this.id,this.pointerEnabled&&!i.style.pointerEvents&&(i.style.pointerEvents="visible")},_render:function(t,e){this.onUpdate&&this.onUpdate(e)===!1||(t.transform(this),this.visible&&this.alpha>0&&this.render(t,e))},render:function(t,i){if("dom"!==t.renderType){var r=t.canvas,n=this.parent,a=t._domElementContainer;t._domElementContainer||(a=t._domElementContainer=e.createElement("div",{style:{position:"absolute",transform:"scale3d("+n.scaleX+","+n.scaleY+", 1)",transformOrigin:"0 0",zIndex:"1"}}),r.parentNode.insertBefore(t._domElementContainer,r.nextSibling));var o,s=this.drawable.domElement,h=this.depth,l=a.childNodes[0];if(s.parentNode)return;for(;l&&3!=l.nodeType&&(o=parseInt(l.style.zIndex)||0,!(o<=0||o>h));)l=l.nextSibling;a.insertBefore(this.drawable.domElement,l)}else t.draw(this)}});return a},{requires:["hilo/core/Hilo","hilo/core/Class","hilo/view/View","hilo/view/Drawable"]}),KISSY.add("hilo/view/Graphics",function(t,e,i,r,n){var a=function(){var t=document.createElement("canvas"),o=t.getContext&&t.getContext("2d");return i.create({Extends:r,Mixes:n,constructor:function(t){t=t||{},this.id=this.id||t.id||e.getUid("Graphics"),a.superclass.constructor.call(this,t),this._actions=[]},lineWidth:1,lineAlpha:1,lineCap:null,lineJoin:null,miterLimit:10,hasStroke:!1,strokeStyle:"0",hasFill:!1,fillStyle:"0",fillAlpha:0,lineStyle:function(t,e,i,r,n,a){var o=this,s=o._addAction;return s.call(o,["lineWidth",o.lineWidth=t||1]),s.call(o,["strokeStyle",o.strokeStyle=e||"0"]),s.call(o,["lineAlpha",o.lineAlpha=i||1]),void 0!=r&&s.call(o,["lineCap",o.lineCap=r]),void 0!=n&&s.call(o,["lineJoin",o.lineJoin=n]),void 0!=a&&s.call(o,["miterLimit",o.miterLimit=a]),o.hasStroke=!0,o},setLineDash:function(t){return this._addAction(["setLineDash",t])},beginFill:function(t,e){var i=this,r=i._addAction;return r.call(i,["fillStyle",i.fillStyle=t]),r.call(i,["fillAlpha",i.fillAlpha=e||1]),i.hasFill=!0,i},endFill:function(){var t=this,e=t._addAction;return t.hasStroke&&e.call(t,["stroke"]),t.hasFill&&e.call(t,["fill"]),t.setCacheDirty(!0),t},beginLinearGradientFill:function(t,e,i,r,n,a){for(var s=this,h=o.createLinearGradient(t,e,i,r),l=0,c=n.length;l1?a.slice(1):null;"function"==typeof t[o]?t[o].apply(t,s):t[o]=a[1]}},render:function(t,e){var i=this;"canvas"===t.renderType?i._draw(t.context):(i.cache(),t.draw(i))},clear:function(){var t=this;return t._actions.length=0,t.lineWidth=1,t.lineAlpha=1,t.lineCap=null,t.lineJoin=null,t.miterLimit=10,t.hasStroke=!1,t.strokeStyle="0",t.hasFill=!1,t.fillStyle="0",t.fillAlpha=1,t.setCacheDirty(!0),t},_addAction:function(t){var e=this;return e._actions.push(t),e}})}();return a},{requires:["hilo/core/Hilo","hilo/core/Class","hilo/view/View","hilo/view/CacheMixin"]}),KISSY.add("hilo/view/Text",function(t,e,i,r,n){var a=e.create({Extends:r,Mixes:n,constructor:function(t){t=t||{},this.id=this.id||t.id||i.getUid("Text"),a.superclass.constructor.call(this,t),t.font||(this.font="12px arial"),this._fontHeight=a.measureFontHeight(this.font)},text:"",color:"#000",textAlign:null,textVAlign:null,outline:!1,lineSpacing:0,maxWidth:200,font:null,textWidth:0,textHeight:0,setFont:function(t){var e=this;return e.font!==t&&(e.font=t,e._fontHeight=a.measureFontHeight(t)),e},render:function(t,e){var i=this;if("canvas"===t.renderType)this.drawable?t.draw(i):i._draw(t.context);else if("dom"===t.renderType){var r=i.drawable,n=r.domElement,a=n.style;a.font=i.font,a.textAlign=i.textAlign,a.color=i.color,a.width=i.width+"px",a.height=i.height+"px",a.lineHeight=i._fontHeight+i.lineSpacing+"px",n.innerHTML=i.text,t.draw(this)}else i.cache(),t.draw(i)},_draw:function(t){var e=this,i=e.text.toString();if(i){t.font=e.font,t.textAlign=e.textAlign,t.textBaseline="top";var r,n,a,o,s,h=i.split(/\r\n|\r|\n|/),l=0,c=0,u=e._fontHeight+e.lineSpacing,d=[];for(r=0,o=h.length;re.maxWidth?(d.push({text:m,y:c}),l>1;break;case"bottom":_=e.height-e.textHeight}var x=e.background;for(x&&(t.fillStyle=x,t.fillRect(0,0,e.width,e.height)),e.outline?t.strokeStyle=e.color:t.fillStyle=e.color,r=0;r>1;break;case"right":case"end":n=a}r.outline?t.strokeText(e,n,i):t.fillText(e,n,i)},Statics:{measureFontHeight:function(t){var e,r=document.documentElement,n=i.createElement("div",{style:{font:t,position:"absolute"},innerHTML:"M"});return r.appendChild(n),e=n.offsetHeight,r.removeChild(n),e}}});return a},{requires:["hilo/core/Class","hilo/core/Hilo","hilo/view/View","hilo/view/CacheMixin"]}),KISSY.add("hilo/view/BitmapText",function(t,e,i,r,n){var a=e.create({Extends:r,constructor:function(t){t=t||{},this.id=this.id||t.id||i.getUid("BitmapText"),a.superclass.constructor.call(this,t);var e=t.text+"";e&&(this.text="",this.setText(e)),this.pointerChildren=!1},glyphs:null,letterSpacing:0,text:"",textAlign:"left",setText:function(t){var e=this,i=t.toString(),r=i.length;if(e.text!=i){e.text=i;var n,a,o,s,h=0,l=0,c=0;for(n=0;n0?e.letterSpacing:0),e.children[n]?(s=e.children[n],s.setImage(o.image,o.rect)):(s=e._createBitmap(o),e.addChild(s)),s.x=c,h=c+o.rect[2],l=Math.max(l,o.rect[3]));for(n=e.children.length-1;n>=r;n--)e._releaseBitmap(e.children[n]),e.children[n].removeFromParent();return e.width=h,e.height=l,this.setTextAlign(),e}},_createBitmap:function(t){var e;return a._pool.length?(e=a._pool.pop(),e.setImage(t.image,t.rect)):e=new n({image:t.image,rect:t.rect}),e},_releaseBitmap:function(t){a._pool.push(t)},setTextAlign:function(t){switch(this.textAlign=t||this.textAlign,this.textAlign){case"center":this.pivotX=.5*this.width;break;case"right":this.pivotX=this.width;break;case"left":default:this.pivotX=0}return this},hasGlyphs:function(t){var e=this.glyphs;if(!e)return!1;t=t.toString();var i,r=t.length;for(i=0;i=this._targetFPS?(this._measuredFPS=1e3/(this._tickTime/this._tickCount)+.5>>0,this._tickCount=0,this._tickTime=0):this._tickTime+=t-this._lastTime,this._lastTime=t;for(var r=i.slice(0),n=0,a=r.length;n=0&&e.splice(i,1)},nextTick:function(t){var e=this,i={tick:function(r){e.removeTick(i),t()}};return e.addTick(i),i},timeout:function(t,e){var i=this,r=(new Date).getTime()+e,n={tick:function(){var e=(new Date).getTime(),a=e-r;a>=0&&(i.removeTick(n),t())}};return i.addTick(n),n},interval:function(t,e){var i=this,r=(new Date).getTime()+e,n={tick:function(){var i=(new Date).getTime(),n=i-r;n>=0&&(n=r)return-1;for(e<0&&(e=r+e),i=e;i=1?1:s;var l=n.ease?n.ease(s):s;n.reverse&&n.isStart&&(n._reverseFlag<0&&(s=1-s,l=1-l),s<1e-7&&(n.repeat>0&&n._repeatCount++>=n.repeat||0==n.repeat&&!n.loop?h=!0:(n._startTime=t(),n._pausedTime=0,n._reverseFlag*=-1))),n.isStart||(n.setProps(n._fromProps,n._toProps),n.isStart=!0,n.onStart&&n.onStart.call(n,n)),n.time=a,n._render(l),(o=n.onUpdate)&&o.call(n,s,n),s>=1&&(n.reverse?(n._startTime=t(),n._pausedTime=0,n._reverseFlag*=-1):n.loop||n.repeat>0&&n._repeatCount++0&&u<=e?(c._render(s),c.time=a,i.add(c)):n.isComplete&&(u<0||u>e)&&c.start()}return n.isComplete?((o=n.onComplete)&&o.call(n,n),!0):void 0}}},Statics:{_tweens:[],tick:function(){var e,r,n=i._tweens,a=n.length;for(r=0;r-1&&n.splice(e,1);else for(e=0;e=i)return void t.fire("complete");if(t._currentIndexe.z})},tick:function(){this.sortZ()}});return o}();return r},{requires:["hilo/core/Class","hilo/util/util"]}),KISSY.add("hilo/game/ParticleSystem",function(t,e,i,r,n,a,o){var s=function(){function t(t,e){return e?t+2*(Math.random()-.5)*e:t}for(var s=["x","y","vx","vy","ax","ay","rotation","rotationV","scale","scaleV","alpha","alphaV","life"],h=[],l=0,c=s.length;l=this._emitTime&&(this._currentRunTime=0,this._emitTime=t(this.emitTime,this.emitTimeVar),this._emit()),this._totalRunTime>=this.totalTime&&this.stop())},_emit:function(){for(var e=t(this.emitNum,this.emitNumVar)>>0,i=0;i=0;e--)this.children[e].destroy()}}),v=i.create({Extends:r,constructor:function(t){this.id=this.id||t.id||e.getUid("Particle"),v.superclass.constructor.call(this,t),this.init(t)},onUpdate:function(t){if(t*=.001,this._died)return!1;var e=this.ax+this.system.gx,i=this.ay+this.system.gy;return this.vx+=e*t,this.vy+=i*t,this.x+=this.vx*t,this.y+=this.vy*t,this.rotation+=this.rotationV,this._time>.1&&(this.alpha+=this.alphaV),this.scale+=this.scaleV,this.scaleX=this.scaleY=this.scale,this._time+=t,this._time>=this.life||this.alpha<=0?(this.destroy(),!1):void 0},setImage:function(t,e){this.drawable=this.drawable||new a,e=e||[0,0,t.width,t.height],this.width=e[2],this.height=e[3],this.drawable.rect=e,this.drawable.image=t},destroy:function(){this._died=!0,this.alpha=0,this.removeFromParent(),f.push(this)},init:function(e){this.system=e.system,this._died=!1,this._time=0,this.alpha=1;for(var i=0,r=h.length;i>0]),this.setImage(e.image,o),void 0!==e.pivotX&&(this.pivotX=e.pivotX*o[2]),void 0!==e.pivotY&&(this.pivotY=e.pivotY*o[3])}},Statics:{create:function(t){if(f.length>0){var e=f.pop();return e.init(t),e}return new v(t)}}});return p}();return s},{requires:["hilo/core/Hilo","hilo/core/Class","hilo/view/View","hilo/view/Container","hilo/view/Drawable","hilo/util/util"]}); \ No newline at end of file diff --git a/build/kissy/hilo-kissy.zip b/build/kissy/hilo-kissy.zip index f8fb04e2..61ae6721 100644 Binary files a/build/kissy/hilo-kissy.zip and b/build/kissy/hilo-kissy.zip differ diff --git a/build/kissy/hilo/core/Class.js b/build/kissy/hilo/core/Class.js index 58217569..fe09b328 100644 --- a/build/kissy/hilo/core/Class.js +++ b/build/kissy/hilo/core/Class.js @@ -1,5 +1,5 @@ /** - * Hilo 1.5.0 for kissy + * Hilo 1.6.0 for kissy * Copyright 2016 alibaba.com * Licensed under the MIT License */ diff --git a/build/kissy/hilo/core/Class.min.js b/build/kissy/hilo/core/Class.min.js index 38083b73..c629628a 100644 --- a/build/kissy/hilo/core/Class.min.js +++ b/build/kissy/hilo/core/Class.min.js @@ -1,5 +1,5 @@ /** - * Hilo 1.5.0 for kissy + * Hilo 1.6.0 for kissy * Copyright 2016 alibaba.com * Licensed under the MIT License */ diff --git a/build/kissy/hilo/core/Hilo.js b/build/kissy/hilo/core/Hilo.js index 7d49336f..dfb15d20 100644 --- a/build/kissy/hilo/core/Hilo.js +++ b/build/kissy/hilo/core/Hilo.js @@ -1,5 +1,5 @@ /** - * Hilo 1.5.0 for kissy + * Hilo 1.6.0 for kissy * Copyright 2016 alibaba.com * Licensed under the MIT License */ @@ -27,7 +27,7 @@ var Hilo = { * Hilo version * @type String */ - version: '1.5.0', + version: '1.6.0', /** * @language=en * Gets a globally unique id. Such as Stage1, Bitmap2 etc. diff --git a/build/kissy/hilo/core/Hilo.min.js b/build/kissy/hilo/core/Hilo.min.js index 41b4957a..b17e2515 100644 --- a/build/kissy/hilo/core/Hilo.min.js +++ b/build/kissy/hilo/core/Hilo.min.js @@ -1,6 +1,6 @@ /** - * Hilo 1.5.0 for kissy + * Hilo 1.6.0 for kissy * Copyright 2016 alibaba.com * Licensed under the MIT License */ -KISSY.add("hilo/core/Hilo",function(t,e,a){var r=window,o=document,i=o.documentElement,n=0,s={},c={version:"1.5.0",getUid:function(t){var e=++n;if(t){var a=t.charCodeAt(t.length-1);return a>=48&&a<=57&&(t+="_"),t+e}return e},viewToString:function(t){for(var e,a=t;a;)e=e?a.id+"."+e:a.id,a=a.parent;return e},copy:function(t,e,r){return a.copy(t,e,r),s.copy||(s.copy=!0,console.warn("Hilo.copy has been Deprecated! Use Hilo.util.copy instead.")),t},browser:e,event:{POINTER_START:e.POINTER_START,POINTER_MOVE:e.POINTER_MOVE,POINTER_END:e.POINTER_END},align:{TOP_LEFT:"TL",TOP:"T",TOP_RIGHT:"TR",LEFT:"L",CENTER:"C",RIGHT:"R",BOTTOM_LEFT:"BL",BOTTOM:"B",BOTTOM_RIGHT:"BR"},getElementRect:function(t){var e;try{e=t.getBoundingClientRect()}catch(a){e={top:t.offsetTop,left:t.offsetLeft,right:t.offsetLeft+t.offsetWidth,bottom:t.offsetTop+t.offsetHeight}}var o=(r.pageXOffset||i.scrollLeft)-(i.clientLeft||0)||0,n=(r.pageYOffset||i.scrollTop)-(i.clientTop||0)||0,s=r.getComputedStyle?getComputedStyle(t):t.currentStyle,c=parseInt,h=c(s.paddingLeft)+c(s.borderLeftWidth)||0,d=c(s.paddingTop)+c(s.borderTopWidth)||0,f=c(s.paddingRight)+c(s.borderRightWidth)||0,l=c(s.paddingBottom)+c(s.borderBottomWidth)||0,g=e.top||0,p=e.left||0,m=e.right||0,T=e.bottom||0;return{left:p+o+h,top:g+n+d,width:m-f-p-h,height:T-l-g-d}},createElement:function(t,e){var a,r,i,n=o.createElement(t);for(a in e)if(r=e[a],"style"===a)for(i in r)n.style[i]=r[i];else n[a]=r;return n},getElement:function(t){return o.getElementById(t)},setElementStyleByView:function(t){var e=t.drawable,a=e.domElement.style,r=t._stateCache||(t._stateCache={}),o=c.browser.jsVendor,i="px",n=!1;if(this.cacheStateIfChanged(t,["visible"],r)&&(a.display=t.visible?"":"none"),this.cacheStateIfChanged(t,["alpha"],r)&&(a.opacity=t.alpha),t.visible&&!(t.alpha<=0)){if(this.cacheStateIfChanged(t,["width"],r)&&(a.width=t.width+i),this.cacheStateIfChanged(t,["height"],r)&&(a.height=t.height+i),this.cacheStateIfChanged(t,["depth"],r)&&(a.zIndex=t.depth+1),t.transform){var s=t.transform;(n=this.cacheStateIfChanged(t,["pivotX","pivotY"],r))&&(a[o+"TransformOrigin"]="0 0"),a[o+"Transform"]="matrix3d("+s.a+", "+s.b+", 0, 0, "+s.c+", "+s.d+", 0, 0, 0, 0, 1, 0, "+s.tx+", "+s.ty+", 0, 1)"}else(n=this.cacheStateIfChanged(t,["pivotX","pivotY"],r))&&(a[o+"TransformOrigin"]=t.pivotX+i+" "+t.pivotY+i),(this.cacheStateIfChanged(t,["x","y","rotation","scaleX","scaleY"],r)||n)&&(a[o+"Transform"]=this.getTransformCSS(t));this.cacheStateIfChanged(t,["background"],r)&&(a.backgroundColor=t.background),a.pointerEvents||(a.pointerEvents="none");var h=e.image;if(h){var d=h.src;d!==r.image&&(r.image=d,a.backgroundImage="url("+d+")");var f=e.rect;if(f){var l=f[0],g=f[1];l!==r.sx&&(r.sx=l,a.backgroundPositionX=-l+i),g!==r.sy&&(r.sy=g,a.backgroundPositionY=-g+i)}}var p=t.mask;if(p){var m=p.drawable.domElement.style.backgroundImage;m!==r.maskImage&&(r.maskImage=m,a[o+"MaskImage"]=m,a[o+"MaskRepeat"]="no-repeat");var T=p.x,u=p.y;T===r.maskX&&u===r.maskY||(r.maskX=T,r.maskY=u,a[o+"MaskPosition"]=T+i+" "+u+i)}}},cacheStateIfChanged:function(t,e,a){var r,o,i,n,s=!1;for(r=0,o=e.length;r=48&&a<=57&&(t+="_"),t+e}return e},viewToString:function(t){for(var e,a=t;a;)e=e?a.id+"."+e:a.id,a=a.parent;return e},copy:function(t,e,r){return a.copy(t,e,r),s.copy||(s.copy=!0,console.warn("Hilo.copy has been Deprecated! Use Hilo.util.copy instead.")),t},browser:e,event:{POINTER_START:e.POINTER_START,POINTER_MOVE:e.POINTER_MOVE,POINTER_END:e.POINTER_END},align:{TOP_LEFT:"TL",TOP:"T",TOP_RIGHT:"TR",LEFT:"L",CENTER:"C",RIGHT:"R",BOTTOM_LEFT:"BL",BOTTOM:"B",BOTTOM_RIGHT:"BR"},getElementRect:function(t){var e;try{e=t.getBoundingClientRect()}catch(a){e={top:t.offsetTop,left:t.offsetLeft,right:t.offsetLeft+t.offsetWidth,bottom:t.offsetTop+t.offsetHeight}}var o=(r.pageXOffset||i.scrollLeft)-(i.clientLeft||0)||0,n=(r.pageYOffset||i.scrollTop)-(i.clientTop||0)||0,s=r.getComputedStyle?getComputedStyle(t):t.currentStyle,c=parseInt,h=c(s.paddingLeft)+c(s.borderLeftWidth)||0,d=c(s.paddingTop)+c(s.borderTopWidth)||0,f=c(s.paddingRight)+c(s.borderRightWidth)||0,l=c(s.paddingBottom)+c(s.borderBottomWidth)||0,g=e.top||0,p=e.left||0,m=e.right||0,T=e.bottom||0;return{left:p+o+h,top:g+n+d,width:m-f-p-h,height:T-l-g-d}},createElement:function(t,e){var a,r,i,n=o.createElement(t);for(a in e)if(r=e[a],"style"===a)for(i in r)n.style[i]=r[i];else n[a]=r;return n},getElement:function(t){return o.getElementById(t)},setElementStyleByView:function(t){var e=t.drawable,a=e.domElement.style,r=t._stateCache||(t._stateCache={}),o=c.browser.jsVendor,i="px",n=!1;if(this.cacheStateIfChanged(t,["visible"],r)&&(a.display=t.visible?"":"none"),this.cacheStateIfChanged(t,["alpha"],r)&&(a.opacity=t.alpha),t.visible&&!(t.alpha<=0)){if(this.cacheStateIfChanged(t,["width"],r)&&(a.width=t.width+i),this.cacheStateIfChanged(t,["height"],r)&&(a.height=t.height+i),this.cacheStateIfChanged(t,["depth"],r)&&(a.zIndex=t.depth+1),t.transform){var s=t.transform;(n=this.cacheStateIfChanged(t,["pivotX","pivotY"],r))&&(a[o+"TransformOrigin"]="0 0"),a[o+"Transform"]="matrix3d("+s.a+", "+s.b+", 0, 0, "+s.c+", "+s.d+", 0, 0, 0, 0, 1, 0, "+s.tx+", "+s.ty+", 0, 1)"}else(n=this.cacheStateIfChanged(t,["pivotX","pivotY"],r))&&(a[o+"TransformOrigin"]=t.pivotX+i+" "+t.pivotY+i),(this.cacheStateIfChanged(t,["x","y","rotation","scaleX","scaleY"],r)||n)&&(a[o+"Transform"]=this.getTransformCSS(t));this.cacheStateIfChanged(t,["background"],r)&&(a.backgroundColor=t.background),a.pointerEvents||(a.pointerEvents="none");var h=e.image;if(h){var d=h.src;d!==r.image&&(r.image=d,a.backgroundImage="url("+d+")");var f=e.rect;if(f){var l=f[0],g=f[1];l!==r.sx&&(r.sx=l,a.backgroundPositionX=-l+i),g!==r.sy&&(r.sy=g,a.backgroundPositionY=-g+i)}}var p=t.mask;if(p){var m=p.drawable.domElement.style.backgroundImage;m!==r.maskImage&&(r.maskImage=m,a[o+"MaskImage"]=m,a[o+"MaskRepeat"]="no-repeat");var T=p.x,u=p.y;T===r.maskX&&u===r.maskY||(r.maskX=T,r.maskY=u,a[o+"MaskPosition"]=T+i+" "+u+i)}}},cacheStateIfChanged:function(t,e,a){var r,o,i,n,s=!1;for(r=0,o=e.length;r=r)return void e.fire("complete");if(e._currentIndex=o)return void e.fire("complete");if(e._currentIndex= 48 && charCode <= 57) prefix += "_"; //0至9之间添加下划线 - return prefix + id; - } - return id; - }, - - /** - * @language=en - * Generates a string representation that contains a path to the specified visual object. Such as Stage1.Container2.Bitmap3. - * @param {View} view Specified visual object. - * @returns {String} String representation of the visual object. - */ - viewToString: function(view) { - var result, obj = view; - while (obj) { - result = result ? (obj.id + '.' + result) : obj.id; - obj = obj.parent; - } - return result; - }, - - /** - * @language=en - * Simple shallow copy objects. - * @deprecated use Hilo.util.copy instead - * @param {Object} target Target object to copy to. - * @param {Object} source Source object to copy. - * @param {Boolean} strict Indicates whether replication is undefined property, default is false, i.e., undefined attributes are not copied. - * @returns {Object} Object after copying. - */ - copy: function(target, source, strict) { - util.copy(target, source, strict); - if (!hasWarnedDict.copy) { - hasWarnedDict.copy = true; - console.warn('Hilo.copy has been Deprecated! Use Hilo.util.copy instead.'); - } - return target; - }, - - /** - * @language=en - * Browser feature set includes: - * @see browser - */ - browser: browser, - - /** - * @language=en - * Event enumeration objects include: - *
    - *
  • POINTER_START - Mouse or touch start event. Corresponds to touchstart or mousedown.
  • - *
  • POINTER_MOVE - Mouse or touch move event. Corresponds to touchmove or mousemove.
  • - *
  • POINTER_END - Mouse or touch end event. Corresponds to touchend or mouseup.
  • - *
- */ - event: { - POINTER_START: browser.POINTER_START, - POINTER_MOVE: browser.POINTER_MOVE, - POINTER_END: browser.POINTER_END - }, - - /** - * @language=en - * Visual object alinment enumeration objects include: - *
    - *
  • TOP_LEFT - Align the top left corner.
  • - *
  • TOP - Top center alignment.
  • - *
  • TOP_RIGHT - Align the top right corner.
  • - *
  • LEFT - Left center alignment.
  • - *
  • CENTER - Align center.
  • - *
  • RIGHT - Right center alignment.
  • - *
  • BOTTOM_LEFT - Align the bottom left corner.
  • - *
  • BOTTOM - Bottom center alignment.
  • - *
  • BOTTOM_RIGHT - Align the bottom right corner.
  • - *
- */ - align: { - TOP_LEFT: 'TL', //top & left - TOP: 'T', //top & center - TOP_RIGHT: 'TR', //top & right - LEFT: 'L', //left & center - CENTER: 'C', //center - RIGHT: 'R', //right & center - BOTTOM_LEFT: 'BL', //bottom & left - BOTTOM: 'B', //bottom & center - BOTTOM_RIGHT: 'BR' //bottom & right - }, - - /** - * @language=en - * Get DOM element content in the page display area. - * @param {HTMLElement} elem DOM elements. - * @returns {Object} Viewable area DOM elements. Format is: {left:0, top:0, width:100, height:100}. - */ - getElementRect: function(elem) { - var bounds; - try { - //this fails if it's a disconnected DOM node - bounds = elem.getBoundingClientRect(); - } catch (e) { - bounds = { - top: elem.offsetTop, - left: elem.offsetLeft, - right: elem.offsetLeft + elem.offsetWidth, - bottom: elem.offsetTop + elem.offsetHeight - }; - } - - var offsetX = ((win.pageXOffset || docElem.scrollLeft) - (docElem.clientLeft || 0)) || 0; - var offsetY = ((win.pageYOffset || docElem.scrollTop) - (docElem.clientTop || 0)) || 0; - var styles = win.getComputedStyle ? getComputedStyle(elem) : elem.currentStyle; - var parseIntFn = parseInt; - - var padLeft = (parseIntFn(styles.paddingLeft) + parseIntFn(styles.borderLeftWidth)) || 0; - var padTop = (parseIntFn(styles.paddingTop) + parseIntFn(styles.borderTopWidth)) || 0; - var padRight = (parseIntFn(styles.paddingRight) + parseIntFn(styles.borderRightWidth)) || 0; - var padBottom = (parseIntFn(styles.paddingBottom) + parseIntFn(styles.borderBottomWidth)) || 0; - - var top = bounds.top || 0; - var left = bounds.left || 0; - var right = bounds.right || 0; - var bottom = bounds.bottom || 0; - - return { - left: left + offsetX + padLeft, - top: top + offsetY + padTop, - width: right - padRight - left - padLeft, - height: bottom - padBottom - top - padTop - }; - }, - - /** - * @language=en - * Create a DOM element. You can specify properties and styles. - * @param {String} type DOM element type to be created. Such as: 'div'. - * @param {Object} properties Properties and styles for DOM element. - * @returns {HTMLElement} A DOM element. - */ - createElement: function(type, properties) { - var elem = doc.createElement(type), - p, val, s; - for (p in properties) { - val = properties[p]; - if (p === 'style') { - for (s in val) elem.style[s] = val[s]; - } else { - elem[p] = val; - } - } - return elem; - }, - - /** - * @language=en - * Gets a DOM element according to the parameter id. This method is equivalent to document.getElementById(id). - * @param {String} id id of the DOM element you want to get. - * @returns {HTMLElement} A DOM element. - */ - getElement: function(id) { - return doc.getElementById(id); - }, - - /** - * @language=en - * Set visual object DOM element CSS style. - * @param {View} obj Specifies the CSS style to set the visual object. - * @private - */ - setElementStyleByView: function(obj) { - var drawable = obj.drawable, - style = drawable.domElement.style, - stateCache = obj._stateCache || (obj._stateCache = {}), - prefix = Hilo.browser.jsVendor, - px = 'px', - flag = false; - - if (this.cacheStateIfChanged(obj, ['visible'], stateCache)) { - style.display = !obj.visible ? 'none' : ''; - } - if (this.cacheStateIfChanged(obj, ['alpha'], stateCache)) { - style.opacity = obj.alpha; - } - if (!obj.visible || obj.alpha <= 0) return; - - if (this.cacheStateIfChanged(obj, ['width'], stateCache)) { - style.width = obj.width + px; - } - if (this.cacheStateIfChanged(obj, ['height'], stateCache)) { - style.height = obj.height + px; - } - if (this.cacheStateIfChanged(obj, ['depth'], stateCache)) { - style.zIndex = obj.depth + 1; - } - if (obj.transform){ - var transform = obj.transform; - if (flag = this.cacheStateIfChanged(obj, ['pivotX', 'pivotY'], stateCache)) { - style[prefix + 'TransformOrigin'] = '0 0'; - } - style[prefix + 'Transform'] = 'matrix3d(' + transform.a + ', '+ transform.b + ', 0, 0, '+ transform.c + ', '+ transform.d + ', 0, 0, 0, 0, 1, 0, '+ transform.tx + ', '+ transform.ty + ', 0, 1)'; - } - else{ - if (flag = this.cacheStateIfChanged(obj, ['pivotX', 'pivotY'], stateCache)) { - style[prefix + 'TransformOrigin'] = obj.pivotX + px + ' ' + obj.pivotY + px; - } - - if (this.cacheStateIfChanged(obj, ['x', 'y', 'rotation', 'scaleX', 'scaleY'], stateCache) || flag) { - style[prefix + 'Transform'] = this.getTransformCSS(obj); - } - } - - if (this.cacheStateIfChanged(obj, ['background'], stateCache)) { - style.backgroundColor = obj.background; - } - if (!style.pointerEvents) { - style.pointerEvents = 'none'; - } - - //render image as background - var image = drawable.image; - if (image) { - var src = image.src; - if (src !== stateCache.image) { - stateCache.image = src; - style.backgroundImage = 'url(' + src + ')'; - } - - var rect = drawable.rect; - if (rect) { - var sx = rect[0], - sy = rect[1]; - if (sx !== stateCache.sx) { - stateCache.sx = sx; - style.backgroundPositionX = -sx + px; - } - if (sy !== stateCache.sy) { - stateCache.sy = sy; - style.backgroundPositionY = -sy + px; - } - } - } - - //render mask - var mask = obj.mask; - if (mask) { - var maskImage = mask.drawable.domElement.style.backgroundImage; - if (maskImage !== stateCache.maskImage) { - stateCache.maskImage = maskImage; - style[prefix + 'MaskImage'] = maskImage; - style[prefix + 'MaskRepeat'] = 'no-repeat'; - } - - var maskX = mask.x, - maskY = mask.y; - if (maskX !== stateCache.maskX || maskY !== stateCache.maskY) { - stateCache.maskX = maskX; - stateCache.maskY = maskY; - style[prefix + 'MaskPosition'] = maskX + px + ' ' + maskY + px; - } - } - }, - - /** - * @private - */ - cacheStateIfChanged: function(obj, propNames, stateCache) { - var i, len, name, value, changed = false; - for (i = 0, len = propNames.length; i < len; i++) { - name = propNames[i]; - value = obj[name]; - if (value != stateCache[name]) { - stateCache[name] = value; - changed = true; - } - } - return changed; - }, - - /** - * @language=en - * Generated visual object CSS style transformation. - * @param {View} obj Specifies visual object whose CSS style must be got. - * @returns {String} String representation of the CSS style. - */ - getTransformCSS: function(obj) { - var use3d = this.browser.supportTransform3D, - str3d = use3d ? '3d' : ''; - - return 'translate' + str3d + '(' + (obj.x - obj.pivotX) + 'px, ' + (obj.y - obj.pivotY) + (use3d ? 'px, 0px)' : 'px)') + - 'rotate' + str3d + (use3d ? '(0, 0, 1, ' : '(') + obj.rotation + 'deg)' + - 'scale' + str3d + '(' + obj.scaleX + ', ' + obj.scaleY + (use3d ? ', 1)' : ')'); - } -}; -for(var i in Hilo){window.Hilo[i] = Hilo[i];} -})(window); -/** - * Hilo 1.5.0 for standalone - * Copyright 2016 alibaba.com - * Licensed under the MIT License - */ -(function(window){ -if(!window.Hilo) window.Hilo = {}; - - -/** - * @language=en - * Create Example Class: - *
- * var Bird = Hilo.Class.create({
- *     Extends: Animal,
- *     Mixes: EventMixin,
- *     constructor: function(name){
- *         this.name = name;
- *     },
- *     fly: function(){
- *         console.log('I am flying');
- *     },
- *     Statics: {
- *         isBird: function(bird){
- *             return bird instanceof Bird;
- *         }
- *     }
- * });
- *
- * var swallow = new Bird('swallow');
- * swallow.fly();
- * Bird.isBird(swallow);
- * 
- * @namespace Class Class is created to aid the developer. - * @static - * @module hilo/core/Class - */ -var Class = (function(){ - -/** - * @language=en - * Create a class based on the parameters, properties and methods specified. - * @param {Object} properties Properties and methods to create the class. - *
    - *
  • Extends - Designed to inherit the parent class.
  • - *
  • Mixes - Specifies mixed member collection object.
  • - *
  • Statics - Static property or method specified class.
  • - *
  • constructor - The constructor of specified class.
  • - *
  • Other members of the property or method to create the class.
  • - *
- * @returns {Object} Create classes. - */ -var create = function(properties){ - properties = properties || {}; - var clazz = properties.hasOwnProperty('constructor') ? properties.constructor : function(){}; - implement.call(clazz, properties); - return clazz; -}; - -/** - * @language=en - * @private - */ -var implement = function(properties){ - var proto = {}, key, value; - for(key in properties){ - value = properties[key]; - if(classMutators.hasOwnProperty(key)){ - classMutators[key].call(this, value); - }else{ - proto[key] = value; - } - } - - mix(this.prototype, proto); -}; - -var classMutators = /** @ignore */{ - Extends: function(parent){ - var existed = this.prototype, proto = createProto(parent.prototype); - //inherit static properites - mix(this, parent); - //keep existed properties - mix(proto, existed); - //correct constructor - proto.constructor = this; - //prototype chaining - this.prototype = proto; - //shortcut to parent's prototype - this.superclass = parent.prototype; - }, - - Mixes: function(items){ - items instanceof Array || (items = [items]); - var proto = this.prototype, item; - - while(item = items.shift()){ - mix(proto, item.prototype || item); - } - }, - - Statics: function(properties){ - mix(this, properties); - } -}; - -/** - * @language=en - * @private - */ -var createProto = (function(){ - if(Object.__proto__){ - return function(proto){ - return {__proto__: proto}; - }; - }else{ - var Ctor = function(){}; - return function(proto){ - Ctor.prototype = proto; - return new Ctor(); - }; - } -})(); - -/** - * @language=en - * Mixed property or method. - * @param {Object} target Mixed audiences. - * @param {Object} source The source whose methods and properties are to be mixed. It can support multiple source parameters. - * @returns {Object} Mixed audiences. - */ -var mix = function(target){ - for(var i = 1, len = arguments.length; i < len; i++){ - var source = arguments[i], defineProps; - for(var key in source){ - var prop = source[key]; - if(prop && typeof prop === 'object'){ - if(prop.value !== undefined || typeof prop.get === 'function' || typeof prop.set === 'function'){ - defineProps = defineProps || {}; - defineProps[key] = prop; - continue; - } - } - target[key] = prop; - } - if(defineProps) defineProperties(target, defineProps); - } - - return target; -}; - -var defineProperty, defineProperties; -try{ - defineProperty = Object.defineProperty; - defineProperties = Object.defineProperties; - defineProperty({}, '$', {value:0}); -}catch(e){ - if('__defineGetter__' in Object){ - defineProperty = function(obj, prop, desc){ - if('value' in desc) obj[prop] = desc.value; - if('get' in desc) obj.__defineGetter__(prop, desc.get); - if('set' in desc) obj.__defineSetter__(prop, desc.set); - return obj; - }; - defineProperties = function(obj, props){ - for(var prop in props){ - if(props.hasOwnProperty(prop)){ - defineProperty(obj, prop, props[prop]); - } - } - return obj; - }; - } -} - -return {create:create, mix:mix}; - -})(); - -window.Hilo.Class = Class; -})(window); -/** - * Hilo 1.5.0 for standalone - * Copyright 2016 alibaba.com - * Licensed under the MIT License - */ -(function(window){ -if(!window.Hilo) window.Hilo = {}; -var Class = window.Hilo.Class; - - -/** - * @language=en - * @class Matrix class is a transforming matrix, which declare how points in one coordinate maped to another coordinate. - * @param {Number} a The value affects pixel positioning alongside the x axis when Scale or rotate images. - * @param {Number} b The value affects pixel positioning alongside the y axis when rotate or skew images. - * @param {Number} c The value affects pixel positioning alongside the x axis when rotate or skew images. - * @param {Number} d The value affects pixel positioning alongside the y axis when Scale or rotate images. - * @param {Number} tx The distance to move every point alongside the x axis. - * @param {Number} ty The distance to move every point alongside the y axis. - * @module hilo/geom/Matrix - * @requires hilo/core/Class - */ -var Matrix = Class.create(/** @lends Matrix.prototype */{ - constructor: function(a, b, c, d, tx, ty){ - this.a = a; - this.b = b; - this.c = c; - this.d = d; - this.tx = tx; - this.ty = ty; - }, - - /** - * set - * @param {Number} a - * @param {Number} b - * @param {Number} c - * @param {Number} d - * @param {Number} tx - * @param {Number} ty - */ - set: function(a, b, c, d, tx, ty){ - this.a = a; - this.b = b; - this.c = c; - this.d = d; - this.tx = tx; - this.ty = ty; - - return this; - }, - - /** - * copy - * @param {Matrix} mat - * @return {Matrix} this - */ - copy: function(mat){ - this.a = mat.a; - this.b = mat.b; - this.c = mat.c; - this.d = mat.d; - this.tx = mat.tx; - this.ty = mat.ty; - - return this; - }, - - /** - * clone - * @return {Matrix} - */ - clone: function(){ - return new Matrix().copy(this); - }, - - /** - * @language=en - * Link a Matrix to current Matrix, in order to make geometry effects on these two composed more effective. - * @param {Matrix} mtx Matrix that link to the source matrix. - * @returns {Matrix} A Matrix Object. - */ - concat: function(mtx){ - var args = arguments, - a = this.a, b = this.b, c = this.c, d = this.d, - tx = this.tx, ty = this.ty; - - var ma, mb, mc, md, mx, my; - if(args.length >= 6){ - ma = args[0]; - mb = args[1]; - mc = args[2]; - md = args[3]; - mx = args[4]; - my = args[5]; - } - else{ - ma = mtx.a; - mb = mtx.b; - mc = mtx.c; - md = mtx.d; - mx = mtx.tx; - my = mtx.ty; - } - - this.a = a * ma + b * mc; - this.b = a * mb + b * md; - this.c = c * ma + d * mc; - this.d = c * mb + d * md; - this.tx = tx * ma + ty * mc + mx; - this.ty = tx * mb + ty * md + my; - return this; - }, - - /** - * @language=en - * Rotate the Matrix Object. - * @param {Number} angle The angle to rotate. - * @returns {Matrix} A Matrix object. - */ - rotate: function(angle){ - var sin = Math.sin(angle), cos = Math.cos(angle), - a = this.a, b = this.b, c = this.c, d = this.d, - tx = this.tx, ty = this.ty; - - this.a = a * cos - b * sin; - this.b = a * sin + b * cos; - this.c = c * cos - d * sin; - this.d = c * sin + d * cos; - this.tx = tx * cos - ty * sin; - this.ty = tx * sin + ty * cos; - return this; - }, - - /** - * @language=en - * Scale the Matrix. - * @param {Number} sx The value to multiply those object scale alongside the x axis. - * @param {Number} sy The value to multiply those object scale alongside the y axis. - * @returns {Matrix} A Matrix object. - */ - scale: function(sx, sy){ - this.a *= sx; - this.d *= sy; - this.c *= sx; - this.b *= sy; - this.tx *= sx; - this.ty *= sy; - return this; - }, - - /** - * @language=en - * Translate the Matrix alongside x axis and y axis by dx and dy. - * @param {Number} dx Translate Matrix alongside the x axis to the right (measured in px). - * @param {Number} dy Translate Matrix alongside the y axis to the right (measured in px). - * @returns {Matrix} A Matrix object. - */ - translate: function(dx, dy){ - this.tx += dx; - this.ty += dy; - return this; - }, - - /** - * @language=en - * Set each Matrix property a value to trigger null transform. The Matrix after applying identity matrix transformation will be exactly the same as original. - * @returns {Matrix} A Matrix object. - */ - identity: function(){ - this.a = this.d = 1; - this.b = this.c = this.tx = this.ty = 0; - return this; - }, - - /** - * @language=en - * Apply an invert transformation of original Matrix. Using this invert transformation, you can reset a Matrix to a state before it had been apply some Matrix. - * @returns {Matrix} A Matrix object. - */ - invert: function(){ - var a = this.a; - var b = this.b; - var c = this.c; - var d = this.d; - var tx = this.tx; - var i = a * d - b * c; - - this.a = d / i; - this.b = -b / i; - this.c = -c / i; - this.d = a / i; - this.tx = (c * this.ty - d * tx) / i; - this.ty = -(a * this.ty - b * tx) / i; - return this; - }, - - /** - * @language=en - * Return the result after apply a Matrix displaying transform on the point. - * @param {Object} point Point need to transform. - * @param {Boolean} round Whether ceil the coordinate values of the point. - * @param {Boolean} returnNew Whether return a new point. - * @returns {Object} 由应用矩阵转换所产生的点。 - */ - transformPoint: function(point, round, returnNew){ - var x = point.x * this.a + point.y * this.c + this.tx, - y = point.x * this.b + point.y * this.d + this.ty; - - if(round){ - x = x + 0.5 >> 0; - y = y + 0.5 >> 0; - } - if(returnNew) return {x:x, y:y}; - point.x = x; - point.y = y; - return point; - } - -}); - -window.Hilo.Matrix = Matrix; -})(window); -/** - * Hilo 1.5.0 for standalone - * Copyright 2016 alibaba.com - * Licensed under the MIT License - */ -(function(window){ -if(!window.Hilo) window.Hilo = {}; -var Class = window.Hilo.Class; - - -/** - * @language=en - * @class EventMixin is a mixin on event related functions. Use Class.mix(target, EventMixin) to add event function onto target. - * @static - * @mixin - * @module hilo/event/EventMixin - * @requires hilo/core/Class - */ -var EventMixin = /** @lends EventMixin# */{ - _listeners: null, - - /** - * @language=en - * Add an event listenser. - * @param {String} type Event type to listen. - * @param {Function} listener Callback function of event listening. - * @param {Boolean} once Listen on event only once and no more response after the first response? - * @returns {Object} The Event itself. Functions chain call supported. - */ - on: function(type, listener, once){ - var listeners = (this._listeners = this._listeners || {}); - var eventListeners = (listeners[type] = listeners[type] || []); - for(var i = 0, len = eventListeners.length; i < len; i++){ - var el = eventListeners[i]; - if(el.listener === listener) return; - } - eventListeners.push({listener:listener, once:once}); - return this; - }, - - /** - * @language=en - * Remove one event listener. Remove all event listeners if no parameter provided, and remove all event listeners on one type which is provided as the only parameter. - * @param {String} type The type of event listener that want to remove. - * @param {Function} listener Event listener callback function to be removed. - * @returns {Object} The Event itself. Functions chain call supported. - */ - off: function(type, listener){ - //remove all event listeners - if(arguments.length == 0){ - this._listeners = null; - return this; - } - - var eventListeners = this._listeners && this._listeners[type]; - if(eventListeners){ - //remove event listeners by specified type - if(arguments.length == 1){ - delete this._listeners[type]; - return this; - } - - for(var i = 0, len = eventListeners.length; i < len; i++){ - var el = eventListeners[i]; - if(el.listener === listener){ - eventListeners.splice(i, 1); - if(eventListeners.length === 0) delete this._listeners[type]; - break; - } - } - } - return this; - }, - - /** - * @language=en - * Send events. If the first parameter is an Object, take it as an Event Object. - * @param {String} type Event type to send. - * @param {Object} detail The detail (parameters go with the event) of Event to send. - * @returns {Boolean} Whether Event call successfully. - */ - fire: function(type, detail){ - var event, eventType; - if(typeof type === 'string'){ - eventType = type; - }else{ - event = type; - eventType = type.type; - } - - var listeners = this._listeners; - if(!listeners) return false; - - var eventListeners = listeners[eventType]; - if(eventListeners){ - var eventListenersCopy = eventListeners.slice(0); - event = event || new EventObject(eventType, this, detail); - if(event._stopped) return false; - - for(var i = 0; i < eventListenersCopy.length; i++){ - var el = eventListenersCopy[i]; - el.listener.call(this, event); - if(el.once) { - var index = eventListeners.indexOf(el); - if(index > -1){ - eventListeners.splice(index, 1); - } - } - } - - if(eventListeners.length == 0) delete listeners[eventType]; - return true; - } - return false; - } -}; - -/** - * @language=en - * Event Object class. It's an private class now, but maybe will become a public class if needed. - */ -var EventObject = Class.create({ - constructor: function EventObject(type, target, detail){ - this.type = type; - this.target = target; - this.detail = detail; - this.timeStamp = +new Date(); - }, - - type: null, - target: null, - detail: null, - timeStamp: 0, - - stopImmediatePropagation: function(){ - this._stopped = true; - } -}); - -//Trick: `stopImmediatePropagation` compatibility -var RawEvent = window.Event; -if(RawEvent){ - var proto = RawEvent.prototype, - stop = proto.stopImmediatePropagation; - proto.stopImmediatePropagation = function(){ - stop && stop.call(this); - this._stopped = true; - }; -} - -window.Hilo.EventMixin = EventMixin; -})(window); -/** - * Hilo 1.5.0 for standalone - * Copyright 2016 alibaba.com - * Licensed under the MIT License - */ -(function(window){ -if(!window.Hilo) window.Hilo = {}; -var Class = window.Hilo.Class; -var util = window.Hilo.util; - - -/** - * @language=en - * @class Drawable is a wrapper of drawable images. - * @param {Object} properties create Objects properties, contains all writable properties. - * @module hilo/view/Drawable - * @requires hilo/core/Class - * @requires hilo/util/util - * @property {Object} image Image to be drawed, can used by CanvasRenderingContext2D.drawImage,like HTMLImageElement、HTMLCanvasElement、HTMLVideoElement。 - * @property {array} rect The retangle area that image will be drawed. - */ -var Drawable = Class.create(/** @lends Drawable.prototype */{ - constructor: function(properties){ - this.init(properties); - }, - - image: null, - rect: null, - - /** - * @language=en - * Initialize drawable elements. - * @param {Object} properties Properties need to be initialized. - */ - init: function(properties){ - var me = this, oldImage = me.image; - if(Drawable.isDrawable(properties)){ - me.image = properties; - }else{ - util.copy(me, properties, true); - } - - var image = me.image; - if(typeof image === 'string'){ - if(oldImage && image === oldImage.getAttribute('src')){ - image = me.image = oldImage; - }else{ - me.image = null; - //load image dynamically - var img = new Image(); - if(properties.crossOrigin){ - img.crossOrigin = "Anonymous"; - } - img.onload = function(){ - img.onload = null; - me.init(img); - }; - img.src = image; - return; - } - } - - if(image && !me.rect) me.rect = [0, 0, image.width, image.height]; - }, - - Statics: /** @lends Drawable */{ - /** - * @language=en - * Check whether the given 'elem' and be wrapped into Drawable object. - * @param {Object} elem Element to be tested. - * @return {Boolean} Return true if element can be wrapped into Drawable element, otherwises return false. - */ - isDrawable: function(elem){ - if(!elem || !elem.tagName) return false; - var tagName = elem.tagName.toLowerCase(); - return tagName === "img" || tagName === "canvas" || tagName === "video"; - } - } -}); -window.Hilo.Drawable = Drawable; -})(window); -/** - * Hilo 1.5.0 for standalone - * Copyright 2016 alibaba.com - * Licensed under the MIT License - */ -(function(window){ -if(!window.Hilo) window.Hilo = {}; -var Class = window.Hilo.Class; -var util = window.Hilo.util; - - -/** - * @language=en - * @class Renderer Renderer is the base class of renderer. - * @param {Object} properties The properties to create a renderer, contains all writeable props of this class. - * @module hilo/renderer/Renderer - * @requires hilo/core/Class - * @requires hilo/util/util - * @property {Object} canvas The canvas of renderer. It can be a dom element, such as a div element, or a canvas element. readonly. - * @property {Object} stage The stage of renderer, readonly. - * @property {String} renderType The render type of renderer, readonly. - */ -var Renderer = Class.create(/** @lends Renderer.prototype */{ - constructor: function(properties){ - properties = properties || {}; - util.copy(this, properties, true); - }, - - renderType:null, - canvas: null, - stage: null, - blendMode:'source-over', - - /** - * @language=en - * Prepare for draw visual object. The subclass need to implement it. - * @param {View} target The visual target to draw. - */ - startDraw: function(target){ }, - - /** - * @language=en - * Draw the visual object. The subclass need to implement it. - * @param {View} target The visual target to draw. - */ - draw: function(target){ }, - - /** - * @language=en - * The handling method after draw the visual object. The subclass need to implement it. - * @param {View} target The visual target to draw. - */ - endDraw: function(target){ }, - - /** - * @language=en - * Transfrom the visual object. The subclass need to implement it. - */ - transform: function(){ }, - - /** - * @language=en - * Hide the visual object. The subclass need to implement it. - */ - hide: function(){ }, - - /** - * @language=en - * Remove the visual object from canvas. Notice that it dosen't remove the object from stage. The subclass need to implement it. - * @param {View} target The visual target to remove. - */ - remove: function(target){ }, - - /** - * @language=en - * Clear the given region of canvas. The subclass need to implement it. - * @param {Number} x The position on the x axis of the given region. - * @param {Number} y The position on the y axis of the given region. - * @param {Number} width The width of the given region. - * @param {Number} height The height of the given region. - */ - clear: function(x, y, width, height){ }, - - /** - * @language=en - * Resize the renderer's canvas. - * @param {Number} width The width of renderer's canvas. - * @param {Number} height The height of the renderer's canvas. - */ - resize: function(width, height){ } - -}); -window.Hilo.Renderer = Renderer; -})(window); -/** - * Hilo 1.5.0 for standalone - * Copyright 2016 alibaba.com - * Licensed under the MIT License - */ -(function(window){ -if(!window.Hilo) window.Hilo = {}; -var Class = window.Hilo.Class; -var Hilo = window.Hilo;var Renderer = window.Hilo.Renderer; - - -/** - * @language=en - * @class CanvasRenderer CanvasRenderer, all the visual object is drawing on the canvas element.The stage will create different renderer depend on the canvas and renderType properties, developer need not use this class directly. - * @augments Renderer - * @param {Object} properties The properties to create a renderer, contains all writeable props of this class. - * @module hilo/renderer/CanvasRenderer - * @requires hilo/core/Class - * @requires hilo/core/Hilo - * @requires hilo/renderer/Renderer - * @property {CanvasRenderingContext2D} context The context of the canvas element, readonly. - */ -var CanvasRenderer = Class.create( /** @lends CanvasRenderer.prototype */ { - Extends: Renderer, - constructor: function(properties) { - CanvasRenderer.superclass.constructor.call(this, properties); - - this.context = this.canvas.getContext("2d"); - }, - renderType: 'canvas', - context: null, - - /** - * @private - * @see Renderer#startDraw - */ - startDraw: function(target) { - if (target.visible && target.alpha > 0) { - if (target === this.stage) { - this.context.clearRect(0, 0, target.width, target.height); - } - if (target.blendMode !== this.blendMode) { - this.context.globalCompositeOperation = this.blendMode = target.blendMode; - } - this.context.save(); - return true; - } - return false; - }, - - /** - * @private - * @see Renderer#draw - */ - draw: function(target) { - var ctx = this.context, - w = target.width, - h = target.height; - - //draw background - var bg = target.background; - if (bg) { - ctx.fillStyle = bg; - ctx.fillRect(0, 0, w, h); - } - - //draw image - var drawable = target.drawable, - image = drawable && drawable.image; - if (image) { - var rect = drawable.rect, - sw = rect[2], - sh = rect[3], - offsetX = rect[4], - offsetY = rect[5]; - //ie9+浏览器宽高为0时会报错 fixed ie9 bug. - if (!sw || !sh) { - return; - } - if (!w && !h) { - //fix width/height TODO: how to get rid of this? - w = target.width = sw; - h = target.height = sh; - } - //the pivot is the center of frame if has offset, otherwise is (0, 0) - if (offsetX || offsetY) ctx.translate(offsetX - sw * 0.5, offsetY - sh * 0.5); - ctx.drawImage(image, rect[0], rect[1], sw, sh, 0, 0, w, h); - } - }, - - /** - * @private - * @see Renderer#endDraw - */ - endDraw: function(target) { - this.context.restore(); - }, - - /** - * @private - * @see Renderer#transform - */ - transform: function(target) { - var drawable = target.drawable; - if (drawable && drawable.domElement) { - Hilo.setElementStyleByView(target); - return; - } - - var ctx = this.context, - scaleX = target.scaleX, - scaleY = target.scaleY; - - if (target === this.stage) { - var style = this.canvas.style, - oldScaleX = target._scaleX, - oldScaleY = target._scaleY, - isStyleChange = false; - - if ((!oldScaleX && scaleX != 1) || (oldScaleX && oldScaleX != scaleX)) { - target._scaleX = scaleX; - style.width = scaleX * target.width + "px"; - isStyleChange = true; - } - if ((!oldScaleY && scaleY != 1) || (oldScaleY && oldScaleY != scaleY)) { - target._scaleY = scaleY; - style.height = scaleY * target.height + "px"; - isStyleChange = true; - } - if (isStyleChange) { - target.updateViewport(); - } - } else { - var x = target.x, - y = target.y, - pivotX = target.pivotX, - pivotY = target.pivotY, - rotation = target.rotation % 360, - transform = target.transform, - mask = target.mask; - - if (mask) { - mask._render(this); - ctx.clip(); - } - - //alignment - var align = target.align; - if (align) { - var pos = target.getAlignPosition(); - x = pos.x; - y = pos.y; - } - - if (transform) { - ctx.transform(transform.a, transform.b, transform.c, transform.d, transform.tx, transform.ty); - } else { - if (x != 0 || y != 0) ctx.translate(x, y); - if (rotation != 0) ctx.rotate(rotation * Math.PI / 180); - if (scaleX != 1 || scaleY != 1) ctx.scale(scaleX, scaleY); - if (pivotX != 0 || pivotY != 0) ctx.translate(-pivotX, -pivotY); - } - - } - - if (target.alpha > 0) ctx.globalAlpha *= target.alpha; - }, - - /** - * @private - * @see Renderer#remove - */ - remove: function(target) { - var drawable = target.drawable; - var elem = drawable && drawable.domElement; - - if (elem) { - var parentElem = elem.parentNode; - if (parentElem) { - parentElem.removeChild(elem); - } - } - }, - - /** - * @private - * @see Renderer#clear - */ - clear: function(x, y, width, height) { - this.context.clearRect(x, y, width, height); - }, - - /** - * @private - * @see Renderer#resize - */ - resize: function(width, height) { - var canvas = this.canvas; - var stage = this.stage; - var style = canvas.style; - - canvas.width = width; - canvas.height = height; - - style.width = stage.width * stage.scaleX + 'px'; - style.height = stage.height * stage.scaleY + 'px'; - } - -}); -window.Hilo.CanvasRenderer = CanvasRenderer; -})(window); -/** - * Hilo 1.5.0 for standalone - * Copyright 2016 alibaba.com - * Licensed under the MIT License - */ -(function(window){ -if(!window.Hilo) window.Hilo = {}; -var Class = window.Hilo.Class; -var Hilo = window.Hilo;var Renderer = window.Hilo.Renderer; -var Drawable = window.Hilo.Drawable; - - -/** - * @language=en - * @class DomRenderer The DomRenderer, all the visual object is drawing using dom element.The stage will create different renderer depend on the canvas and renderType properties, developer need not use this class directly. - * @augments Renderer - * @param {Object} properties The properties to create a renderer, contains all writeable props of this class. - * @module hilo/renderer/DOMRenderer - * @requires hilo/core/Class - * @requires hilo/core/Hilo - * @requires hilo/renderer/Renderer - * @requires hilo/view/Drawable - */ -var DOMRenderer = (function(){ - -return Class.create({ - Extends: Renderer, - constructor: function(properties){ - DOMRenderer.superclass.constructor.call(this, properties); - }, - renderType:'dom', - /** - * @private - * @see Renderer#startDraw - */ - startDraw: function(target){ - //prepare drawable - var drawable = (target.drawable = target.drawable || new Drawable()); - drawable.domElement = drawable.domElement || createDOMDrawable(target, drawable); - return true; - }, - - /** - * @private - * @see Renderer#draw - */ - draw: function(target){ - var parent = target.parent, - targetElem = target.drawable.domElement, - currentParent = targetElem.parentNode; - - if(parent){ - var parentElem = parent.drawable.domElement; - if(parentElem != currentParent){ - parentElem.appendChild(targetElem); - } - //fix image load bug - if(!target.width && !target.height){ - var rect = target.drawable.rect; - if(rect && (rect[2] || rect[3])){ - target.width = rect[2]; - target.height = rect[3]; - } - } - } - else if(target === this.stage && !currentParent){ - targetElem.style.overflow = 'hidden'; - this.canvas.appendChild(targetElem); - } - }, - - /** - * @private - * @see Renderer#transform - */ - transform: function(target){ - Hilo.setElementStyleByView(target); - if(target === this.stage){ - var style = this.canvas.style, - oldScaleX = target._scaleX, - oldScaleY = target._scaleY, - scaleX = target.scaleX, - scaleY = target.scaleY; - - if((!oldScaleX && scaleX != 1) || (oldScaleX && oldScaleX != scaleX)){ - target._scaleX = scaleX; - style.width = scaleX * target.width + "px"; - } - if((!oldScaleY && scaleY != 1) || (oldScaleY && oldScaleY != scaleY)){ - target._scaleY = scaleY; - style.height = scaleY * target.height + "px"; - } - } - }, - - /** - * @private - * @see Renderer#remove - */ - remove: function(target){ - var drawable = target.drawable; - var elem = drawable && drawable.domElement; - - if(elem){ - var parentElem = elem.parentNode; - if(parentElem){ - parentElem.removeChild(elem); - } - } - }, - - /** - * @private - * @see Renderer#hide - */ - hide: function(target){ - var elem = target.drawable && target.drawable.domElement; - if(elem) elem.style.display = 'none'; - }, - - /** - * @private - * @see Renderer#resize - */ - resize: function(width, height){ - var style = this.canvas.style; - style.width = width + 'px'; - style.height = height + 'px'; - if(style.position != "absolute") { - style.position = "relative"; - } - } -}); - -/** - * @language=en - * Create a dom element, you can set the tagName property,such as canvas and div. - * @param {Object} view A visual object. - * @param {Object} imageObj The image object to render, include the image propertiy and other associated properties, such as rect. - * @return {HTMLElement} The created dom element. - * @private - */ -function createDOMDrawable(view, imageObj){ - var tag = view.tagName || "div", - img = imageObj.image, - w = view.width || (img && img.width), - h = view.height || (img && img.height), - elem = Hilo.createElement(tag), style = elem.style; - - if(view.id) elem.id = view.id; - style.position = "absolute"; - style.left = (view.left || 0) + "px"; - style.top = (view.top || 0) + "px"; - style.width = w + "px"; - style.height = h + "px"; - - if(tag == "canvas"){ - elem.width = w; - elem.height = h; - if(img){ - var ctx = elem.getContext("2d"); - var rect = imageObj.rect || [0, 0, w, h]; - ctx.drawImage(img, rect[0], rect[1], rect[2], rect[3], - (view.x || 0), (view.y || 0), - (view.width || rect[2]), - (view.height || rect[3])); - } - }else{ - style.opacity = view.alpha != undefined ? view.alpha : 1; - if(view === this.stage || view.clipChildren) style.overflow = "hidden"; - if(img && img.src){ - style.backgroundImage = "url(" + img.src + ")"; - var bgX = view.rectX || 0, bgY = view.rectY || 0; - style.backgroundPosition = (-bgX) + "px " + (-bgY) + "px"; - } - } - return elem; -} - -})(); - -window.Hilo.DOMRenderer = DOMRenderer; -})(window); -/** - * Hilo 1.5.0 for standalone - * Copyright 2016 alibaba.com - * Licensed under the MIT License - */ -(function(window){ -if(!window.Hilo) window.Hilo = {}; -var Class = window.Hilo.Class; -var Hilo = window.Hilo;var Renderer = window.Hilo.Renderer; -var Matrix = window.Hilo.Matrix; - - -/** - * Heavily inspired by PIXI's SpriteRenderer: - * https://github.com/pixijs/pixi.js/blob/v3.0.9/src/core/sprites/webgl/SpriteRenderer.js - */ - -var DEG2RAD = Math.PI / 180; -/** - * @language=en - * @class WebGLRenderer The WebGLRenderer, all the visual object is drawing on the canvas using WebGL.The stage will create different renderer depend on the canvas and renderType properties, developer need not use this class directly. - * @augments Renderer - * @param {Object} properties The properties to create a renderer, contains all writeable props of this class. - * @module hilo/renderer/WebGLRenderer - * @requires hilo/core/Class - * @requires hilo/core/Hilo - * @requires hilo/renderer/Renderer - * @requires hilo/geom/Matrix - * @property {WebGLRenderingContext} gl The WebGL context of the renderer, readonly. - */ -var WebGLRenderer = Class.create(/** @lends WebGLRenderer.prototype */{ - Extends: Renderer, - Statics:/** @lends WebGLRenderer */{ - /** - * @language=en - * The max num of batch draw, default is 2000. - * @type {Number} - */ - MAX_BATCH_NUM:2000, - /** - * @language=en - * The num of vertex attributes, readonly. - * @type {Number} - */ - ATTRIBUTE_NUM:5, - /** - * @language=en - * is WebGL supported, readonly. - * @type {Boolean} - */ - isSupport:function(){ - if(this._isSupported == undefined){ - var canvas = document.createElement('canvas'); - if(canvas.getContext && (canvas.getContext('webgl')||canvas.getContext('experimental-webgl'))){ - this._isSupported = true; - } - else{ - this._isSupported = false; - } - } - return this._isSupported; - }, - /** - * WebGL context Options - * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/getContextAttributes - * @type {Object} - */ - contextOptions: null - }, - renderType:'webgl', - gl:null, - _isContextLost:false, - _cacheTexture:{}, - constructor: function(properties){ - WebGLRenderer.superclass.constructor.call(this, properties); - var that = this; - var contextOptions = WebGLRenderer.contextOptions || {}; - this.gl = this.canvas.getContext("webgl", contextOptions)||this.canvas.getContext('experimental-webgl', contextOptions); - - this.maxBatchNum = WebGLRenderer.MAX_BATCH_NUM; - this.positionStride = WebGLRenderer.ATTRIBUTE_NUM * 4; - var vertexNum = this.maxBatchNum * WebGLRenderer.ATTRIBUTE_NUM * 4; - var indexNum = this.maxBatchNum * 6; - this.arrayBuffer = new ArrayBuffer(vertexNum * 4); - this.float32Array = new Float32Array(this.arrayBuffer); - this.uint32Array = new Uint32Array(this.arrayBuffer); - this.indexs = new Uint16Array(indexNum); - for (var i=0, j=0; i < indexNum; i += 6, j += 4) - { - this.indexs[i + 0] = j + 0; - this.indexs[i + 1] = j + 1; - this.indexs[i + 2] = j + 2; - this.indexs[i + 3] = j + 1; - this.indexs[i + 4] = j + 2; - this.indexs[i + 5] = j + 3; - } - this.batchIndex = 0; - this.sprites = []; - - this.canvas.addEventListener('webglcontextlost', function(e){ - that._isContextLost = true; - e.preventDefault(); - }, false); - - this.canvas.addEventListener('webglcontextrestored', function(e){ - that._isContextLost = false; - that.setupWebGLStateAndResource(); - }, false); - - this.setupWebGLStateAndResource(); - }, - setupWebGLStateAndResource:function(){ - var gl = this.gl; - gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA); - gl.clearColor(0, 0, 0, 0); - gl.disable(gl.DEPTH_TEST); - gl.disable(gl.CULL_FACE); - gl.enable(gl.BLEND); - - this._cacheTexture = {}; - this._initShaders(); - this.defaultShader.active(); - - this.positionBuffer = gl.createBuffer(); - this.indexBuffer = gl.createBuffer(); - - gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.indexBuffer); - gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, this.indexs, gl.STATIC_DRAW); - - gl.bindBuffer(gl.ARRAY_BUFFER, this.positionBuffer); - gl.bufferData(gl.ARRAY_BUFFER, this.arrayBuffer, gl.DYNAMIC_DRAW); - - gl.vertexAttribPointer(this.a_position, 2, gl.FLOAT, false, this.positionStride, 0);//x, y - gl.vertexAttribPointer(this.a_TexCoord, 2, gl.FLOAT, false, this.positionStride, 2 * 4);//x, y - gl.vertexAttribPointer(this.a_tint, 4, gl.UNSIGNED_BYTE, true, this.positionStride, 4 * 4);//alpha - }, - - context: null, - - /** - * @private - * @see Renderer#startDraw - */ - startDraw: function(target){ - if(target.visible && target.alpha > 0){ - if(target === this.stage){ - this.clear(); - } - return true; - } - return false; - }, - /** - * @private - * @see Renderer#draw - */ - draw: function(target){ - var w = target.width, - h = target.height; - - //TODO:draw background - var bg = target.background; // jshint ignore:line - - //draw image - var drawable = target.drawable, image = drawable && drawable.image; - if(image){ - var rect = drawable.rect, sw = rect[2], sh = rect[3]; - if(!w && !h){ - //fix width/height TODO: how to get rid of this? - w = target.width = sw; - h = target.height = sh; - } - - if(this.batchIndex >= this.maxBatchNum){ - this._renderBatches(); - } - - var vertexs = this._createVertexs(image, rect[0], rect[1], sw, sh, 0, 0, w, h); - var index = this.batchIndex * this.positionStride; - var float32Array = this.float32Array; - var uint32Array = this.uint32Array; - - var tint = (target.tint >> 16) + (target.tint & 0xff00) + ((target.tint & 0xff) << 16) + (target.__webglRenderAlpha * 255 << 24); - - float32Array[index + 0] = vertexs[0];//x - float32Array[index + 1] = vertexs[1];//y - float32Array[index + 2] = vertexs[2];//uvx - float32Array[index + 3] = vertexs[3];//uvy - uint32Array[index + 4] = tint;//tint - - float32Array[index + 5] = vertexs[4]; - float32Array[index + 6] = vertexs[5]; - float32Array[index + 7] = vertexs[6]; - float32Array[index + 8] = vertexs[7]; - uint32Array[index + 9] = tint; - - float32Array[index + 10] = vertexs[8]; - float32Array[index + 11] = vertexs[9]; - float32Array[index + 12] = vertexs[10]; - float32Array[index + 13] = vertexs[11]; - uint32Array[index + 14] = tint; - - float32Array[index + 15] = vertexs[12]; - float32Array[index + 16] = vertexs[13]; - float32Array[index + 17] = vertexs[14]; - float32Array[index + 18] = vertexs[15]; - uint32Array[index + 19] = tint; - - var matrix = target.__webglWorldMatrix; - for(var i = 0;i < 4;i ++){ - var x = float32Array[index + i*5]; - var y = float32Array[index + i*5 + 1]; - - float32Array[index + i*5] = matrix.a*x + matrix.c*y + matrix.tx; - float32Array[index + i*5 + 1] = matrix.b*x + matrix.d*y + matrix.ty; - } - - target.__textureImage = image; - this.sprites[this.batchIndex++] = target; - } - }, - - /** - * @private - * @see Renderer#endDraw - */ - endDraw: function(target){ - if(target === this.stage){ - this._renderBatches(); - } - }, - /** - * @private - * @see Renderer#transform - */ - transform: function(target){ - var drawable = target.drawable; - if(drawable && drawable.domElement){ - Hilo.setElementStyleByView(target); - return; - } - - var scaleX = target.scaleX, - scaleY = target.scaleY; - - if(target === this.stage){ - var style = this.canvas.style, - oldScaleX = target._scaleX, - oldScaleY = target._scaleY, - isStyleChange = false; - - if((!oldScaleX && scaleX != 1) || (oldScaleX && oldScaleX != scaleX)){ - target._scaleX = scaleX; - style.width = scaleX * target.width + "px"; - isStyleChange = true; - } - if((!oldScaleY && scaleY != 1) || (oldScaleY && oldScaleY != scaleY)){ - target._scaleY = scaleY; - style.height = scaleY * target.height + "px"; - isStyleChange = true; - } - if(isStyleChange){ - target.updateViewport(); - } - target.__webglWorldMatrix = target.__webglWorldMatrix||new Matrix(1, 0, 0, 1, 0, 0); - } - else if(target.parent){ - target.__webglWorldMatrix = target.__webglWorldMatrix||new Matrix(1, 0, 0, 1, 0, 0); - this._setConcatenatedMatrix(target, target.parent); - } - - if(target.alpha > 0) { - if(target.parent && target.parent.__webglRenderAlpha){ - target.__webglRenderAlpha = target.alpha * target.parent.__webglRenderAlpha; - } - else{ - target.__webglRenderAlpha = target.alpha; - } - } - }, - - /** - * @private - * @see Renderer#remove - */ - remove: function(target){ - var drawable = target.drawable; - var elem = drawable && drawable.domElement; - - if(elem){ - var parentElem = elem.parentNode; - if(parentElem){ - parentElem.removeChild(elem); - } - } - }, - - /** - * @private - * @see Renderer#clear - */ - clear: function(x, y, width, height){ - this.gl.clear(this.gl.COLOR_BUFFER_BIT); - }, - - /** - * @private - * @see Renderer#resize - */ - resize: function(width, height){ - if(this.width !== width || this.height !== height){ - var canvas = this.canvas; - var stage = this.stage; - var style = canvas.style; - - this.width = canvas.width = width; - this.height = canvas.height = height; - - style.width = stage.width * stage.scaleX + 'px'; - style.height = stage.height * stage.scaleY + 'px'; - - this.gl.viewport(0, 0, width, height); - - this.canvasHalfWidth = width * .5; - this.canvasHalfHeight = height * .5; - - this._uploadProjectionTransform(true); - } - }, - _renderBatches:function(){ - var gl = this.gl; - gl.bufferSubData(gl.ARRAY_BUFFER, 0, this.uint32Array.subarray(0, this.batchIndex * this.positionStride)); - var startIndex = 0; - var batchNum = 0; - var preTextureImage = null; - for(var i = 0;i < this.batchIndex;i ++){ - var sprite = this.sprites[i]; - if(preTextureImage && preTextureImage !== sprite.__textureImage){ - this._renderBatch(startIndex, i); - startIndex = i; - batchNum = 1; - } - preTextureImage = sprite.__textureImage; - } - this._renderBatch(startIndex, this.batchIndex); - this.batchIndex = 0; - }, - _renderBatch:function(start, end){ - var gl = this.gl; - var num = end - start; - if(num > 0){ - gl.bindTexture(gl.TEXTURE_2D, this._getTexture(this.sprites[start])); - gl.drawElements(gl.TRIANGLES, num * 6, gl.UNSIGNED_SHORT, start * 6 * 2); - } - }, - _uploadProjectionTransform:function(force){ - if(!this._projectionTransformElements||force){ - this._projectionTransformElements = new Float32Array([ - 1/this.canvasHalfWidth, 0, 0, - 0, -1/this.canvasHalfHeight, 0, - -1, 1, 1, - ]); - } - - this.gl.uniformMatrix3fv(this.u_projectionTransform, false, this._projectionTransformElements); - }, - _initShaders:function(){ - var VSHADER_SOURCE ='\ - attribute vec2 a_position;\n\ - attribute vec2 a_TexCoord;\n\ - attribute vec4 a_tint;\n\ - uniform mat3 u_projectionTransform;\n\ - varying vec2 v_TexCoord;\n\ - varying vec4 v_tint;\n\ - void main(){\n\ - gl_Position = vec4((u_projectionTransform * vec3(a_position, 1.0)).xy, 1.0, 1.0);\n\ - v_TexCoord = a_TexCoord;\n\ - v_tint = vec4(a_tint.rgb * a_tint.a, a_tint.a);\n\ - }\n\ - '; - - var FSHADER_SOURCE = '\n\ - precision mediump float;\n\ - uniform sampler2D u_Sampler;\n\ - varying vec2 v_TexCoord;\n\ - varying vec4 v_tint;\n\ - void main(){\n\ - gl_FragColor = texture2D(u_Sampler, v_TexCoord) * v_tint;\n\ - }\n\ - '; - - this.defaultShader = new Shader(this, { - v:VSHADER_SOURCE, - f:FSHADER_SOURCE - },{ - attributes:["a_position", "a_TexCoord", "a_tint"], - uniforms:["u_projectionTransform", "u_Sampler"] - }); - }, - _createVertexs:function(img, tx, ty, tw, th, x, y, w, h){ - var tempVertexs = this.__tempVertexs||[]; - var width = img.width; - var height = img.height; - - tw = tw/width; - th = th/height; - tx = tx/width; - ty = ty/height; - - w = w; - h = h; - x = x; - y = y; - - if(tw + tx > 1){ - tw = 1 - tx; - } - - if(th + ty > 1){ - th = 1 - ty; - } - - var index = 0; - tempVertexs[index++] = x; tempVertexs[index++] = y; tempVertexs[index++] = tx; tempVertexs[index++] = ty; - tempVertexs[index++] = x+w;tempVertexs[index++] = y; tempVertexs[index++] = tx+tw; tempVertexs[index++] = ty; - tempVertexs[index++] = x; tempVertexs[index++] = y+h; tempVertexs[index++] = tx;tempVertexs[index++] = ty+th; - tempVertexs[index++] = x+w;tempVertexs[index++] = y+h;tempVertexs[index++] = tx+tw;tempVertexs[index++] = ty+th; - - return tempVertexs; - }, - _setConcatenatedMatrix:function(view, ancestor){ - var mtx = view.__webglWorldMatrix; - var cos = 1, sin = 0, - rotation = view.rotation % 360, - pivotX = view.pivotX, pivotY = view.pivotY, - scaleX = view.scaleX, scaleY = view.scaleY, - transform = view.transform; - - if (transform) { - mtx.copy(transform); - } - else { - if(rotation){ - var r = rotation * DEG2RAD; - cos = Math.cos(r); - sin = Math.sin(r); - } - - var pos = view.getAlignPosition(); - - mtx.a = cos*scaleX; - mtx.b = sin*scaleX; - mtx.c = -sin*scaleY; - mtx.d = cos*scaleY; - mtx.tx = pos.x - mtx.a * pivotX - mtx.c * pivotY; - mtx.ty = pos.y - mtx.b * pivotX - mtx.d * pivotY; - } - - mtx.concat(ancestor.__webglWorldMatrix); - }, - _getTexture:function(sprite){ - var image = sprite.__textureImage; - var texture = this._cacheTexture[image.src]; - if(!texture){ - texture = this.activeShader.uploadTexture(image); - } - return texture; - } -}); - -/** - * @language=en - * shader - * @param {WebGLRenderer} renderer [description] - * @param {Object} source - * @param {String} source.v 顶点shader - * @param {String} source.f 片段shader - * @param {Object} attr - * @param {Array} attr.attributes attribute数组 - * @param {Array} attr.uniforms uniform数组 - */ -var Shader = function(renderer, source, attr){ - this.renderer = renderer; - this.gl = renderer.gl; - this.program = this._createProgram(this.gl, source.v, source.f); - - attr = attr||{}; - this.attributes = attr.attributes||[]; - this.uniforms = attr.uniforms||[]; -}; - -Shader.prototype = { - active:function(){ - var that = this; - var renderer = that.renderer; - var gl = that.gl; - var program = that.program; - - if(program && gl){ - renderer.activeShader = that; - gl.useProgram(program); - that.attributes.forEach(function(attribute){ - renderer[attribute] = gl.getAttribLocation(program, attribute); - gl.enableVertexAttribArray(renderer[attribute]); - }); - - that.uniforms.forEach(function(uniform){ - renderer[uniform] = gl.getUniformLocation(program, uniform); - }); - - if(that.width !== renderer.width || that.height !== renderer.height){ - that.width = renderer.width; - that.height = renderer.height; - renderer._uploadProjectionTransform(); - } - } - }, - uploadTexture:function(image){ - var gl = this.gl; - var renderer = this.renderer; - var texture = gl.createTexture(); - var u_Sampler = renderer.u_Sampler; - - gl.activeTexture(gl.TEXTURE0); - gl.bindTexture(gl.TEXTURE_2D, texture); - - // gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, 1); - gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, 1); - gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image); - - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); - gl.uniform1i(u_Sampler, 0); - gl.bindTexture(gl.TEXTURE_2D, null); - - this.renderer._cacheTexture[image.src] = texture; - return texture; - }, - _createProgram:function(gl, vshader, fshader){ - var vertexShader = this._createShader(gl, gl.VERTEX_SHADER, vshader); - var fragmentShader = this._createShader(gl, gl.FRAGMENT_SHADER, fshader); - if (!vertexShader || !fragmentShader) { - return null; - } - - var program = gl.createProgram(); - if (program) { - gl.attachShader(program, vertexShader); - gl.attachShader(program, fragmentShader); - - gl.linkProgram(program); - - gl.deleteShader(fragmentShader); - gl.deleteShader(vertexShader); - var linked = gl.getProgramParameter(program, gl.LINK_STATUS); - if (!linked) { - var error = gl.getProgramInfoLog(program); - console.log('Failed to link program: ' + error); - gl.deleteProgram(program); - return null; - } - } - return program; - }, - _createShader:function(gl, type, source){ - var shader = gl.createShader(type); - if(shader){ - gl.shaderSource(shader, source); - gl.compileShader(shader); - - var compiled = gl.getShaderParameter(shader, gl.COMPILE_STATUS); - if (!compiled) { - var error = gl.getShaderInfoLog(shader); - console.log('Failed to compile shader: ' + error); - gl.deleteShader(shader); - return null; - } - } - return shader; - } -}; -window.Hilo.WebGLRenderer = WebGLRenderer; -})(window); -/** - * Hilo 1.5.0 for standalone - * Copyright 2016 alibaba.com - * Licensed under the MIT License - */ -(function(window){ -if(!window.Hilo) window.Hilo = {}; -var Hilo = window.Hilo;var Class = window.Hilo.Class; -var EventMixin = window.Hilo.EventMixin; -var Matrix = window.Hilo.Matrix; -var util = window.Hilo.util; - - -/** - * @language=en - * @class View View is the base class of all display objects - * @mixes EventMixin - * @borrows EventMixin#on as #on - * @borrows EventMixin#off as #off - * @borrows EventMixin#fire as #fire - * @param {Object} properties The properties to create a view object, contains all writeable props of this class - * @module hilo/view/View - * @requires hilo/core/Hilo - * @requires hilo/core/Class - * @requires hilo/event/EventMixin - * @requires hilo/geom/Matrix - * @requires hilo/util/util - * @property {String} id The identifier for the view. - * @property {Number} x The position of the view on the x axis relative to the local coordinates of the parent, default value is 0. - * @property {Number} y The position of the view on the y axis relative to the local coordinates of the parent, default value is 0. - * @property {Number} width The width of the view, default value is 0. - * @property {Number} height The height of the view, default value is 0. - * @property {Number} alpha The opacity of the view, default value is 1. - * @property {Number} rotation The rotation of the view in angles, default value is 0. - * @property {Boolean} visible The visibility of the view. If false the vew will not be drawn, default value is true. - * @property {Number} pivotX Position of the center point on the x axis of the view, default value is 0. - * @property {Number} pivotY Position of the center point on the y axis of the view, default value is 0. - * @property {Number} scaleX The x axis scale factor of the view, default value is 1. - * @property {Number} scaleY The y axis scale factor of the view, default value is 1. - * @property {Matrix} transform The transform of the view.If set the transform, x, y, scaleX, scaleY, rotation, pivotX, pivotY will be ignored.default is null. - * @property {Boolean} pointerEnabled Is the view can receive DOM events, default value is true. - * @property {Object} background The background style to fill the view, can be css color, gradient or pattern of canvas - * @property {Graphics} mask Sets a mask for the view. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. A regular mask must be a Hilo.Graphics object. This allows for much faster masking in canvas as it utilises shape clipping. To remove a mask, set this property to null. - * @property {Number} tint The tint applied to the view,default is 0xFFFFFF.Only support in WebGL mode. - * @property {String|Function} align The alignment of the view, the value must be one of Hilo.align enum. - * @property {Container} parent The parent view of this view, readonly! - * @property {Number} depth The z index of the view, readonly! - * @property {Drawable} drawable The drawable object of the view. Only for advanced develop. - * @property {Array} boundsArea The vertex points of the view, the points are relative to the center point. This is a example: [{x:10, y:10}, {x:20, y:20}]. - */ -var View = (function(){ - -return Class.create(/** @lends View.prototype */{ - Mixes: EventMixin, - constructor: function(properties){ - properties = properties || {}; - this.id = this.id || properties.id || Hilo.getUid("View"); - util.copy(this, properties, true); - }, - - tint:0xffffff, - id: null, - x: 0, - y: 0, - width: 0, - height: 0, - alpha: 1, - rotation: 0, - visible: true, - pivotX: 0, - pivotY: 0, - scaleX: 1, - scaleY: 1, - pointerEnabled: true, - background: null, - mask: null, - align: null, - drawable: null, - boundsArea: null, - parent: null, - depth: -1, - transform: null, - blendMode:'source-over', - - /** - * @language=en - * Get the stage object of the view. If the view doesn't add to any stage, null will be returned. - * @returns {Stage} The stage object of the view. - */ - getStage: function(){ - var obj = this, parent; - while(parent = obj.parent) obj = parent; - //NOTE: don't use `instanceof` to prevent circular module requirement. - //But it's not a very reliable way to check it's a stage instance. - if(obj.canvas) return obj; - return null; - }, - - /** - * @language=en - * Get the scaled width of the view. - * @returns {Number} scaled width of the view. - */ - getScaledWidth: function(){ - return this.width * this.scaleX; - }, - - /** - * @language=en - * Get the scaled height of the view. - * @returns {Number} scaled height of the view. - */ - getScaledHeight: function(){ - return this.height * this.scaleY; - }, - - /** - * @language=en - * Add current view to a Contaner. - * @param {Container} container Container object. - * @param {Uint} index The index of the view in container. - * @returns {View} Current view. - */ - addTo: function(container, index){ - if(typeof index === 'number') container.addChildAt(this, index); - else container.addChild(this); - return this; - }, - - /** - * @language=en - * Remove current view from it's parent container - * @returns {View} Current view. - */ - removeFromParent: function(){ - var parent = this.parent; - if(parent) parent.removeChild(this); - return this; - }, - - /** - * @language=en - * Get the bounds of the view as a circumscribed rectangle and all vertex points relative to the coordinates of the stage. - * @returns {Array} The vertex points array, and the array contains the following properties: - *
    - *
  • x - The position of the view on the x axis relative to the coordinates of the stage.
  • - *
  • y - The position of the view on the y axis relative to the coordinates of the stage.
  • - *
  • width - The width of circumscribed rectangle of the view.
  • - *
  • height - The height of circumscribed rectangle of the view
  • - *
- */ - getBounds: function(){ - var w = this.width, h = this.height, - mtx = this.getConcatenatedMatrix(), - poly = this.boundsArea || [{x:0, y:0}, {x:w, y:0}, {x:w, y:h}, {x:0, y:h}], - vertexs = [], point, x, y, minX, maxX, minY, maxY; - - for(var i = 0, len = poly.length; i < len; i++){ - point = mtx.transformPoint(poly[i], true, true); - x = point.x; - y = point.y; - - if(i == 0){ - minX = maxX = x; - minY = maxY = y; - }else{ - if(minX > x) minX = x; - else if(maxX < x) maxX = x; - if(minY > y) minY = y; - else if(maxY < y) maxY = y; - } - vertexs[i] = point; - } - - vertexs.x = minX; - vertexs.y = minY; - vertexs.width = maxX - minX; - vertexs.height = maxY - minY; - return vertexs; - }, - - /** - * @language=en - * Get the matrix that can transform points from current view coordinates to the ancestor container coordinates. - * @param {View} ancestor The ancestor of current view, default value is the top container. - * @private - */ - getConcatenatedMatrix: function(ancestor){ - var mtx = new Matrix(1, 0, 0, 1, 0, 0); - - for(var o = this; o != ancestor && o.parent; o = o.parent){ - var cos = 1, sin = 0, - rotation = o.rotation % 360, - pivotX = o.pivotX, pivotY = o.pivotY, - scaleX = o.scaleX, scaleY = o.scaleY, - transform = o.transform; - - if(transform) { - mtx.concat(transform); - } - else{ - if(rotation){ - var r = rotation * Math.PI / 180; - cos = Math.cos(r); - sin = Math.sin(r); - } - - if(pivotX != 0) mtx.tx -= pivotX; - if(pivotY != 0) mtx.ty -= pivotY; - - var pos = o.getAlignPosition(); - mtx.concat(cos*scaleX, sin*scaleX, -sin*scaleY, cos*scaleY, pos.x, pos.y); - } - - } - return mtx; - }, - - getAlignPosition: function(){ - var parent = this.parent; - var align = this.align; - var x = this.x; - var y = this.y; - - if(parent && this.align){ - if(typeof align === 'function'){ - return this.align(); - } - - var w = this.width, h = this.height, - pw = parent.width, ph = parent.height; - switch(align){ - case 'TL': - x = 0; - y = 0; - break; - case 'T': - x = pw - w >> 1; - y = 0; - break; - case 'TR': - x = pw - w; - y = 0; - break; - case 'L': - x = 0; - y = ph - h >> 1; - break; - case 'C': - x = pw - w >> 1; - y = ph - h >> 1; - break; - case 'R': - x = pw - w; - y = ph - h >> 1; - break; - case 'BL': - x = 0; - y = ph - h; - break; - case 'B': - x = pw - w >> 1; - y = ph - h; - break; - case 'BR': - x = pw - w; - y = ph - h; - break; - } - } - - return { - x:x, - y:y - }; - }, - - /** - * @language=en - * Determining whether a point is in the circumscribed rectangle of current view. - * @param {Number} x The x axis relative to the stage coordinates. - * @param {Number} y The y axis relative to the stage coordinates. - * @param {Boolean} usePolyCollision Is use polygon collision, default value is false. - * @returns {Boolean} the point is in the circumscribed rectangle of current view. - */ - hitTestPoint: function(x, y, usePolyCollision){ - var bound = this.getBounds(), - hit = x >= bound.x && x <= bound.x + bound.width && - y >= bound.y && y <= bound.y + bound.height; - - if(hit && usePolyCollision){ - hit = pointInPolygon(x, y, bound); - } - return hit; - }, - - /** - * @language=en - * Determining whether an object is in the circumscribed rectangle of current view. - * @param {View} object The object need to determining. - * @param {Boolean} usePolyCollision Is use polygon collision, default value is false. - */ - hitTestObject: function(object, usePolyCollision){ - var b1 = this.getBounds(), - b2 = object.getBounds(), - hit = b1.x <= b2.x + b2.width && b2.x <= b1.x + b1.width && - b1.y <= b2.y + b2.height && b2.y <= b1.y + b1.height; - - if(hit && usePolyCollision){ - hit = polygonCollision(b1, b2); - } - return !!hit; - }, - - /** - * @language=en - * The method to render current display object. Only for advanced develop. - * @param {Renderer} renderer Renderer object. - * @param {Number} delta The delta time of render. - * @protected - */ - _render: function(renderer, delta){ - if((!this.onUpdate || this.onUpdate(delta) !== false) && renderer.startDraw(this)){ - renderer.transform(this); - this.render(renderer, delta); - renderer.endDraw(this); - } - }, - /** - * @language=en - * Mouse event - */ - _fireMouseEvent:function(e){ - e.eventCurrentTarget = this; - this.fire(e); - - // 处理mouseover事件 mouseover不需要阻止冒泡 - // handle mouseover event, mouseover needn't stop propagation. - if(e.type == "mousemove"){ - if(!this.__mouseOver){ - this.__mouseOver = true; - var overEvent = util.copy({}, e); - overEvent.type = "mouseover"; - this.fire(overEvent); - } - } - else if(e.type == "mouseout"){ - this.__mouseOver = false; - } - - // 向上冒泡 - // handle event propagation - var parent = this.parent; - if(!e._stopped && !e._stopPropagationed && parent){ - if(e.type == "mouseout" || e.type == "touchout"){ - if(!parent.hitTestPoint(e.stageX, e.stageY, true)){ - parent._fireMouseEvent(e); - } - } - else{ - parent._fireMouseEvent(e); - } - } - }, - - /** - * @language=en - * This method will call while the view need update(usually caused by ticker update). This method can return a Boolean value, if return false, the view will not be drawn. - * Limit: If you change the index in it's parent, it will not be drawn correct in current frame but next frame is correct. - * @type Function - * @default null - */ - onUpdate: null, - - /** - * @language=en - * The render method of current view. The subclass can implement it's own render logic by rewrite this function. - * @param {Renderer} renderer Renderer object. - * @param {Number} delta The delta time of render. - */ - render: function(renderer, delta){ - renderer.draw(this); - }, - - /** - * @language=en - * Get a string representing current view. - * @returns {String} string representing current view. - */ - toString: function(){ - return Hilo.viewToString(this); - } -}); - -/** - * @language=en - * @private - */ -function pointInPolygon(x, y, poly){ - var cross = 0, onBorder = false, minX, maxX, minY, maxY; - - for(var i = 0, len = poly.length; i < len; i++){ - var p1 = poly[i], p2 = poly[(i+1)%len]; - - if(p1.y == p2.y && y == p1.y){ - p1.x > p2.x ? (minX = p2.x, maxX = p1.x) : (minX = p1.x, maxX = p2.x); - if(x >= minX && x <= maxX){ - onBorder = true; - continue; - } - } - - p1.y > p2.y ? (minY = p2.y, maxY = p1.y) : (minY = p1.y, maxY = p2.y); - if(y < minY || y > maxY) continue; - - var nx = (y - p1.y)*(p2.x - p1.x) / (p2.y - p1.y) + p1.x; - if(nx > x) cross++; - else if(nx == x) onBorder = true; - - //当射线和多边形相交 - if(p1.x > x && p1.y == y){ - var p0 = poly[(len+i-1)%len]; - //当交点的两边在射线两旁 - if(p0.y < y && p2.y > y || p0.y > y && p2.y < y){ - cross ++; - } - } - } - - return onBorder || (cross % 2 == 1); -} - -/** - * @language=en - * @private - */ -function polygonCollision(poly1, poly2){ - var result = doSATCheck(poly1, poly2, {overlap:-Infinity, normal:{x:0, y:0}}); - if(result) return doSATCheck(poly2, poly1, result); - return false; -} - -/** - * @language=en - * @private - */ -function doSATCheck(poly1, poly2, result){ - var len1 = poly1.length, len2 = poly2.length, - currentPoint, nextPoint, distance, - min1, max1, min2, max2, dot, overlap, normal = {x:0, y:0}; - - for(var i = 0; i < len1; i++){ - currentPoint = poly1[i]; - nextPoint = poly1[(i < len1-1 ? i+1 : 0)]; - - normal.x = currentPoint.y - nextPoint.y; - normal.y = nextPoint.x - currentPoint.x; - - distance = Math.sqrt(normal.x * normal.x + normal.y * normal.y); - normal.x /= distance; - normal.y /= distance; - - min1 = max1 = poly1[0].x * normal.x + poly1[0].y * normal.y; - for(var j = 1; j < len1; j++){ - dot = poly1[j].x * normal.x + poly1[j].y * normal.y; - if(dot > max1) max1 = dot; - else if(dot < min1) min1 = dot; - } - - min2 = max2 = poly2[0].x * normal.x + poly2[0].y * normal.y; - for(j = 1; j < len2; j++){ - dot = poly2[j].x * normal.x + poly2[j].y * normal.y; - if(dot > max2) max2 = dot; - else if(dot < min2) min2 = dot; - } - - if(min1 < min2){ - overlap = min2 - max1; - normal.x = -normal.x; - normal.y = -normal.y; - }else{ - overlap = min1 - max2; - } - - if(overlap >= 0){ - return false; - }else if(overlap > result.overlap){ - result.overlap = overlap; - result.normal.x = normal.x; - result.normal.y = normal.y; - } - } - - return result; -} - -})(); -window.Hilo.View = View; -})(window); -/** - * Hilo 1.5.0 for standalone - * Copyright 2016 alibaba.com - * Licensed under the MIT License - */ -(function(window){ -if(!window.Hilo) window.Hilo = {}; -var Drawable = window.Hilo.Drawable; -var browser = window.Hilo.browser; - - -var _cacheCanvas, _cacheContext; -/** - * @language=en - * @class CacheMixin A mixin that contains cache method.You can mix cache method to the target by use Class.mix(target, CacheMixin). - * @static - * @mixin - * @module hilo/view/CacheMixin - * @requires hilo/view/Drawable - * @requires hilo/util/browser - */ -var CacheMixin = /** @lends CacheMixin# */ { - _cacheDirty:true, - /** - * @language=en - * Cache the view. - * @param {Boolean} forceUpdate is force update cache. - */ - cache: function(forceUpdate){ - if(forceUpdate || this._cacheDirty || !this.drawable){ - this.updateCache(); - } - }, - /** - * @language=en - * Update the cache. - */ - updateCache:function(){ - if(browser.supportCanvas){ - if(!_cacheCanvas){ - _cacheCanvas = document.createElement('canvas'); - _cacheContext = _cacheCanvas.getContext('2d'); - } - - //TODO:width, height自动判断 - _cacheCanvas.width = this.width; - _cacheCanvas.height = this.height; - this._draw(_cacheContext); - this.drawable = this.drawable||new Drawable(); - this.drawable.init({ - image:_cacheCanvas.toDataURL() - }); - this._cacheDirty = false; - } - }, - /** - * @language=en - * set the cache state diry. - * @param {Boolean} dirty is cache dirty - */ - setCacheDirty:function(dirty){ - this._cacheDirty = dirty; - } -}; -window.Hilo.CacheMixin = CacheMixin; -})(window); -/** - * Hilo 1.5.0 for standalone - * Copyright 2016 alibaba.com - * Licensed under the MIT License - */ -(function(window){ -if(!window.Hilo) window.Hilo = {}; -var Hilo = window.Hilo;var Class = window.Hilo.Class; -var View = window.Hilo.View; - - -/** - * @language=en - * @class Container is the base class to all container classes. Each Container can add other view object as children. - * @augments View - * @param {Object} properties Properties parameters of the object to create. Contains all writable properties of this class. - * @module hilo/view/Container - * @requires hilo/core/Hilo - * @requires hilo/core/Class - * @requires hilo/view/View - * @property {Array} children List of children elements of the container, readonly! - * @property {Boolean} pointerChildren Whether children elements of the container can response to user interactive events, default value is true. - * @property {Boolean} clipChildren Whether clip children elements which are out of the container, default value is false. - */ -var Container = Class.create(/** @lends Container.prototype */{ - Extends: View, - constructor: function(properties){ - properties = properties || {}; - this.id = this.id || properties.id || Hilo.getUid("Container"); - Container.superclass.constructor.call(this, properties); - - if(this.children) this._updateChildren(); - else this.children = []; - }, - - children: null, - pointerChildren: true, - clipChildren: false, - - /** - * @language=en - * Return the amount of the children elements of the container. - * @returns {Uint} The amount of the children elements of the container. - */ - getNumChildren: function(){ - return this.children.length; - }, - - /** - * @language=en - * Add child element at given index. - * @param {View} child Element to add. - * @param {Number} index The given index position, range from 0. - */ - addChildAt: function(child, index){ - var children = this.children, - len = children.length, - parent = child.parent; - - index = index < 0 ? 0 : index > len ? len : index; - var childIndex = this.getChildIndex(child); - if(childIndex == index){ - return this; - }else if(childIndex >= 0){ - children.splice(childIndex, 1); - index = index == len ? len - 1 : index; - }else if(parent){ - parent.removeChild(child); - } - - children.splice(index, 0, child); - - //直接插入,影响插入位置之后的深度 - //Insert directly, this will affect depth of elements after the index. - if(childIndex < 0){ - this._updateChildren(index); - } - //只是移动时影响中间段的深度 - //Will affect depth of elements in the middle during moving - else{ - var startIndex = childIndex < index ? childIndex : index; - var endIndex = childIndex < index ? index : childIndex; - this._updateChildren(startIndex, endIndex + 1); - } - - return this; - }, - - /** - * @language=en - * Add child element at the top. - * @param {View} child Elements to add. - */ - addChild: function(child){ - var total = this.children.length, - args = arguments; - - for(var i = 0, len = args.length; i < len; i++){ - this.addChildAt(args[i], total + i); - } - return this; - }, - - /** - * @language=en - * Remove element at the index. - * @param {Int} index Index of the element to remove, range from 0. - * @returns {View} Element had been removed. - */ - removeChildAt: function(index){ - var children = this.children; - if(index < 0 || index >= children.length) return null; - - var child = children[index]; - if(child){ - //NOTE: use `__renderer` for fixing child removal (DOMRenderer and FlashRenderer only). - //Do `not` use it in any other case. - if(!child.__renderer){ - var obj = child; - while(obj = obj.parent){ - //obj is stage - if(obj.renderer){ - child.__renderer = obj.renderer; - break; - } - else if(obj.__renderer){ - child.__renderer = obj.__renderer; - break; - } - } - } - - if(child.__renderer){ - child.__renderer.remove(child); - } - - child.parent = null; - child.depth = -1; - } - - children.splice(index, 1); - this._updateChildren(index); - - return child; - }, - - /** - * @language=en - * Remove the given child element. - * @param {View} child The child element to remove. - * @returns {View} Element had been removed. - */ - removeChild: function(child){ - return this.removeChildAt(this.getChildIndex(child)); - }, - - /** - * @language=en - * Remove child element by its id. - * @param {String} id The id of element to remove. - * @returns {View} Element had been removed. - */ - removeChildById: function(id){ - var children = this.children, child; - for(var i = 0, len = children.length; i < len; i++){ - child = children[i]; - if(child.id === id){ - this.removeChildAt(i); - return child; - } - } - return null; - }, - - /** - * @language=en - * Remove all children elements. - * @returns {Container} Container itself. - */ - removeAllChildren: function(){ - while(this.children.length) this.removeChildAt(0); - return this; - }, - - /** - * @language=en - * Return child element at the given index. - * @param {Number} index The index of the element, range from 0. - */ - getChildAt: function(index){ - var children = this.children; - if(index < 0 || index >= children.length) return null; - return children[index]; - }, - - /** - * @language=en - * Return child element at the given id. - * @param {String} id The id of child element to return. - */ - getChildById: function(id){ - var children = this.children, child; - for(var i = 0, len = children.length; i < len; i++){ - child = children[i]; - if(child.id === id) return child; - } - return null; - }, - - /** - * @language=en - * Return index value of the given child element. - * @param {View} child The child element need to get its index. - */ - getChildIndex: function(child){ - return this.children.indexOf(child); - }, - - /** - * @language=en - * Set the index of child element. - * @param {View} child The child element need to set index. - * @param {Number} index The index to set to the element. - */ - setChildIndex: function(child, index){ - var children = this.children, - oldIndex = children.indexOf(child); - - if(oldIndex >= 0 && oldIndex != index){ - var len = children.length; - index = index < 0 ? 0 : index >= len ? len - 1 : index; - children.splice(oldIndex, 1); - children.splice(index, 0, child); - this._updateChildren(); - } - return this; - }, - - /** - * @language=en - * Swap index between two child elements. - * @param {View} child1 Child element A. - * @param {View} child2 Child element B. - */ - swapChildren: function(child1, child2){ - var children = this.children, - index1 = this.getChildIndex(child1), - index2 = this.getChildIndex(child2); - - child1.depth = index2; - children[index2] = child1; - child2.depth = index1; - children[index1] = child2; - }, - - /** - * @language=en - * Swap two children elements at given indexes. - * @param {Number} index1 Given index A. - * @param {Number} index2 Given index B. - */ - swapChildrenAt: function(index1, index2){ - var children = this.children, - child1 = this.getChildAt(index1), - child2 = this.getChildAt(index2); - - child1.depth = index2; - children[index2] = child1; - child2.depth = index1; - children[index1] = child2; - }, - - /** - * @language=en - * Sort children elements by the given key or function. - * @param {Object} keyOrFunction If is String, sort children elements by the given property string; If is Function, sort by the function. - */ - sortChildren: function(keyOrFunction){ - var fn = keyOrFunction, - children = this.children; - if(typeof fn == "string"){ - var key = fn; - fn = function(a, b){ - return b[key] - a[key]; - }; - } - children.sort(fn); - this._updateChildren(); - }, - - /** - * @language=en - * Update children elements. - * @private - */ - _updateChildren: function(start, end){ - var children = this.children, child; - start = start || 0; - end = end || children.length; - for(var i = start; i < end; i++){ - child = children[i]; - child.depth = i + 1; - child.parent = this; - } - }, - - /** - * @language=en - * Return whether this container contains the parameter described child element. - * @param {View} child The child element to test. - */ - contains: function(child){ - while(child = child.parent){ - if(child === this){ - return true; - } - } - return false; - }, - - /** - * @language=en - * Return object at the point positioned by given values on x axis and y axis. - * @param {Number} x The point's value on the coordinate's x axis. - * @param {Number} y The point's value on the coordinate's y asix. - * @param {Boolean} usePolyCollision Whether use polygon collision detection, default value is false. - * @param {Boolean} global Whether return all elements that match the condition, default value is false. - * @param {Boolean} eventMode Whether find elements under event mode, default value is false. - */ - getViewAtPoint: function(x, y, usePolyCollision, global, eventMode){ - var result = global ? [] : null, - children = this.children, child, obj; - - for(var i = children.length - 1; i >= 0; i--){ - child = children[i]; - //skip child which is not shown or pointer enabled - if(!child || !child.visible || child.alpha <= 0 || (eventMode && !child.pointerEnabled)) continue; - //find child recursively - if(child.children && child.children.length && !(eventMode && !child.pointerChildren)){ - obj = child.getViewAtPoint(x, y, usePolyCollision, global, eventMode); - } - - if(obj){ - if(!global) return obj; - else if(obj.length) result = result.concat(obj); - }else if(child.hitTestPoint(x, y, usePolyCollision)){ - if(!global) return child; - else result.push(child); - } - } - - return global && result.length ? result : null; - }, - - /** - * @language=en - * Rewrite render method. - * @private - */ - render: function(renderer, delta){ - Container.superclass.render.call(this, renderer, delta); - - var children = this.children.slice(0), i, len, child; - for(i = 0, len = children.length; i < len; i++){ - child = children[i]; - //NOTE: the child could remove or change it's parent - if(child.parent === this) child._render(renderer, delta); - } - } - -}); - -window.Hilo.Container = Container; -})(window); -/** - * Hilo 1.5.0 for standalone - * Copyright 2016 alibaba.com - * Licensed under the MIT License - */ -(function(window){ -if(!window.Hilo) window.Hilo = {}; -var Hilo = window.Hilo;var Class = window.Hilo.Class; -var Container = window.Hilo.Container; -var CanvasRenderer = window.Hilo.CanvasRenderer; -var DOMRenderer = window.Hilo.DOMRenderer; -var WebGLRenderer = window.Hilo.WebGLRenderer; -var browser = window.Hilo.browser; -var util = window.Hilo.util; - - -/** - * @language=en - * Demo: - *
- * var stage = new Hilo.Stage({
- *     renderType:'canvas',
- *     container: containerElement,
- *     width: 320,
- *     height: 480
- * });
- * 
- * @class Stage is the root of all visual object tree, any visual object will be render only after being added to Stage or any children elements of Stage. Normally, every hilo application start with an stage instance. - * @augments Container - * @param {Object} properties Properties parameters for the object. Includes all writable properties of this class. Some important like: - *
    - *
  • container:String|HTMLElement - Assign the parent container element of the Stage in the page. It should be a dom container or an id. If this parameter is not given and canvas isn't in the dom tree, you should add the stage vanvas into the dom tree yourself, otherwise Stage will not render. optional.
  • - *
  • renderType:String - Renering way: canvas|dom|webgl,default value is canvas, optional.
  • - *
  • canvas:String|HTMLCanvasElement|HTMLElement - 指定舞台所对应的画布元素。它是一个canvas或普通的div,也可以传入元素的id。若为canvas,则使用canvas来渲染所有对象,否则使用dom+css来渲染。可选。
  • - *
  • width:Number
  • - The width of the Stage, default value is the width of canvas, optional. - *
  • height:Number
  • - The height of the Stage, default value is the height of canvas, optional. - *
  • paused:Boolean
  • - Whether stop rendering the Stage, default value is false, optional. - *
- * @module hilo/view/Stage - * @requires hilo/core/Hilo - * @requires hilo/core/Class - * @requires hilo/view/Container - * @requires hilo/renderer/CanvasRenderer - * @requires hilo/renderer/DOMRenderer - * @requires hilo/renderer/WebGLRenderer - * @requires hilo/util/browser - * @requires hilo/util/util - * @property {HTMLCanvasElement|HTMLElement} canvas The canvas the Stage is related to. It can be a canvas or a div element, readonly! - * @property {Renderer} renderer Stage renderer, readonly! - * @property {Boolean} paused Paused Stage rendering. - * @property {Object} viewport Rendering area of the Stage. Including properties like: left, top, width, height. readonly! - */ -var Stage = Class.create(/** @lends Stage.prototype */{ - Extends: Container, - constructor: function(properties){ - properties = properties || {}; - this.id = this.id || properties.id || Hilo.getUid('Stage'); - Stage.superclass.constructor.call(this, properties); - - this._initRenderer(properties); - - //init size - var width = this.width, height = this.height, - viewport = this.updateViewport(); - if(!properties.width) width = (viewport && viewport.width) || 320; - if(!properties.height) height = (viewport && viewport.height) || 480; - this.resize(width, height, true); - }, - - canvas: null, - renderer: null, - paused: false, - viewport: null, - - /** - * @language=en - * @private - */ - _initRenderer: function(properties){ - var canvas = properties.canvas; - var container = properties.container; - var renderType = properties.renderType||'canvas'; - - if(typeof canvas === 'string') canvas = Hilo.getElement(canvas); - if(typeof container === 'string') container = Hilo.getElement(container); - - if(!canvas){ - var canvasTagName = renderType === 'dom'?'div':'canvas'; - canvas = Hilo.createElement(canvasTagName, { - style: { - position: 'absolute' - } - }); - } - else if(!canvas.getContext){ - renderType = 'dom'; - } - - this.canvas = canvas; - if(container) container.appendChild(canvas); - - var props = {canvas:canvas, stage:this}; - switch(renderType){ - case 'dom': - this.renderer = new DOMRenderer(props); - break; - case 'webgl': - if(WebGLRenderer.isSupport()){ - this.renderer = new WebGLRenderer(props); - } - else{ - this.renderer = new CanvasRenderer(props); - } - break; - case 'canvas': - /* falls through */ - default: - this.renderer = new CanvasRenderer(props); - break; - } - }, - - /** - * @language=en - * Add Stage canvas to DOM container. Note: this function overwrite View.addTo function. - * @param {HTMLElement} domElement An dom element. - * @returns {Stage} The Stage Object, chained call supported. - */ - addTo: function(domElement){ - var canvas = this.canvas; - if(canvas.parentNode !== domElement){ - domElement.appendChild(canvas); - } - return this; - }, - - /** - * @language=en - * Invoke tick function and Stage will update and render. Developer may not need to use this funciton. - * @param {Number} delta The time had pass between this tick invoke and last tick invoke. - */ - tick: function(delta){ - if(!this.paused){ - this._render(this.renderer, delta); - } - }, - - /** - * @language=en - * Turn on/off Stage response to DOM event. To make visual objects on the Stage interactive, use this function to turn on Stage's responses to events. - * @param {String|Array} type The event name or array that need to turn on/off. - * @param {Boolean} enabled Whether turn on or off the response method of stage DOM event. If not provided, default value is true. - * @returns {Stage} The Stage Object, chained call supported. - */ - enableDOMEvent: function(types, enabled){ - var me = this, - canvas = me.canvas, - handler = me._domListener || (me._domListener = function(e){me._onDOMEvent(e);}); - - types = typeof types === 'string' ? [types] : types; - enabled = enabled !== false; - - for(var i = 0; i < types.length; i++){ - var type = types[i]; - - if(enabled){ - canvas.addEventListener(type, handler, false); - }else{ - canvas.removeEventListener(type, handler); - } - } - - return me; - }, - - /** - * @language=en - * DOM events handler function. This funciton will invoke events onto the visual object, which is on the position of the coordinate where the events is invoked. - * @private - */ - _onDOMEvent: function(e){ - var type = e.type, event = e, isTouch = type.indexOf('touch') == 0; - - //calculate stageX/stageY - var posObj = e; - if(isTouch){ - var touches = e.touches, changedTouches = e.changedTouches; - posObj = (touches && touches.length) ? touches[0] : - (changedTouches && changedTouches.length) ? changedTouches[0] : null; - } - - var x = posObj.pageX || posObj.clientX, y = posObj.pageY || posObj.clientY, - viewport = this.viewport || this.updateViewport(); - - event.stageX = x = (x - viewport.left) / this.scaleX; - event.stageY = y = (y - viewport.top) / this.scaleY; - - //鼠标事件需要阻止冒泡方法 Prevent bubbling on mouse events. - event.stopPropagation = function(){ - this._stopPropagationed = true; - }; - - var obj = this.getViewAtPoint(x, y, true, false, true)||this, - canvas = this.canvas, target = this._eventTarget; - - //fire mouseout/touchout event for last event target - var leave = type === 'mouseout'; - //当obj和target不同 且obj不是target的子元素时才触发out事件 fire out event when obj and target isn't the same as well as obj is not a child element to target. - if(target && (target != obj && (!target.contains || !target.contains(obj))|| leave)){ - var out = (type === 'touchmove') ? 'touchout' : - (type === 'mousemove' || leave || !obj) ? 'mouseout' : null; - if(out) { - var outEvent = util.copy({}, event); - outEvent.type = out; - outEvent.eventTarget = target; - target._fireMouseEvent(outEvent); - } - event.lastEventTarget = target; - this._eventTarget = null; - } - - //fire event for current view - if(obj && obj.pointerEnabled && type !== 'mouseout'){ - event.eventTarget = this._eventTarget = obj; - obj._fireMouseEvent(event); - } - - //set cursor for current view - if(!isTouch){ - var cursor = (obj && obj.pointerEnabled && obj.useHandCursor) ? 'pointer' : ''; - canvas.style.cursor = cursor; - } - - //fix android: `touchmove` fires only once - if(browser.android && type === 'touchmove'){ - e.preventDefault(); - } - }, - - /** - * @language=en - * Update the viewport (rendering area) which Stage show on the page. Invoke this function to update viewport when Stage canvas changes border, margin or padding properties. - * @returns {Object} The visible area of the Stage (the viewport property). - */ - updateViewport: function(){ - var canvas = this.canvas, viewport = null; - if(canvas.parentNode){ - viewport = this.viewport = Hilo.getElementRect(canvas); - } - return viewport; - }, - - /** - * @language=en - * Resize the Stage. - * @param {Number} width The width of the new Stage. - * @param {Number} height The height of the new Stage. - * @param {Boolean} forceResize Whether forced to resize the Stage, means no matter the size of the Stage, force to change the size to keep Stage, canvas and window act at the same time. - */ - resize: function(width, height, forceResize){ - if(forceResize || this.width !== width || this.height !== height){ - this.width = width; - this.height = height; - this.renderer.resize(width, height); - this.updateViewport(); - } - } - -}); - -window.Hilo.Stage = Stage; -})(window); -/** - * Hilo 1.5.0 for standalone - * Copyright 2016 alibaba.com - * Licensed under the MIT License - */ -(function(window){ -if(!window.Hilo) window.Hilo = {}; -var Hilo = window.Hilo;var Class = window.Hilo.Class; -var View = window.Hilo.View; -var Drawable = window.Hilo.Drawable; - - -/** - * @language=en - * - *
- * Example: - *
- * var bmp = new Hilo.Bitmap({image:imgElem, rect:[0, 0, 100, 100]});
- * stage.addChild(bmp);
- * 
- * @class Bitmap - * @augments View - * @param {Object} properties the options of create Instance.It can contains all writable property and Moreover: - *
    - *
  • image - the image of bitmap which contained, required.
  • - *
  • rect - the range of bitmap in the image, option
  • - *
  • crossOrigin - Whether cross-domain is needed, default is false
  • - *
- * @module hilo/view/Bitmap - * @requires hilo/core/Hilo - * @requires hilo/core/Class - * @requires hilo/view/View - * @requires hilo/view/Drawable - */ - var Bitmap = Class.create(/** @lends Bitmap.prototype */{ - Extends: View, - constructor: function(properties){ - properties = properties || {}; - this.id = this.id || properties.id || Hilo.getUid("Bitmap"); - Bitmap.superclass.constructor.call(this, properties); - - this.drawable = new Drawable(properties); - - //init width and height - if(!this.width || !this.height){ - var rect = this.drawable.rect; - if(rect){ - this.width = rect[2]; - this.height = rect[3]; - } - } - }, - - /** - * @language=en - * set the image。 - * @param {Image|String} Image Object or URL. - * @param {Array} rect the range of bitmap in the image, option. - * @param {Boolean} Whether cross-domain is needed, default is false. - * @returns {Bitmap} self。 - */ - setImage: function(image, rect, crossOrigin){ - this.drawable.init({image:image, rect:rect, crossOrigin:crossOrigin}); - if(rect){ - this.width = rect[2]; - this.height = rect[3]; - } - else if(!this.width && !this.height){ - rect = this.drawable.rect; - if(rect){ - this.width = rect[2]; - this.height = rect[3]; - } - } - return this; - } - }); - -window.Hilo.Bitmap = Bitmap; -})(window); -/** - * Hilo 1.5.0 for standalone - * Copyright 2016 alibaba.com - * Licensed under the MIT License - */ -(function(window){ -if(!window.Hilo) window.Hilo = {}; -var Hilo = window.Hilo;var Class = window.Hilo.Class; -var View = window.Hilo.View; -var Drawable = window.Hilo.Drawable; - - -/** - * @language=en - * - *
- * @class Sprite animation class. - * @augments View - * @module hilo/view/Sprite - * @requires hilo/core/Hilo - * @requires hilo/core/Class - * @requires hilo/view/View - * @requires hilo/view/Drawable - * @param properties Properties parameters for creating object, include all writable properties of this class, also include: - *
    - *
  • frames - Sprite animation frames data object.
  • - *
- * @property {number} currentFrame Current showing frame index, range from 0, readoly! - * @property {boolean} paused Is sprite paused, default value is false. - * @property {boolean} loop Is sprite play in loop, default value is false. - * @property {boolean} timeBased Is sprite animate base on time, default value is false (base on frame). - * @property {number} interval Interval between sprite animation frames. If timeBased is true, measured in ms, otherwise, measured in frames. - */ -var Sprite = Class.create(/** @lends Sprite.prototype */{ - Extends: View, - constructor: function(properties){ - properties = properties || {}; - this.id = this.id || properties.id || Hilo.getUid("Sprite"); - Sprite.superclass.constructor.call(this, properties); - - this._frames = []; - this._frameNames = {}; - this.drawable = new Drawable(); - if(properties.frames) this.addFrame(properties.frames); - }, - - _frames: null, //所有帧的集合 Collection of all frames - _frameNames: null, //带名字name的帧的集合 Collection of frames that with name - _frameElapsed: 0, //当前帧持续的时间或帧数 Elapsed time of current frame. - _firstRender: true, //标记是否是第一次渲染 Is the first render. - - paused: false, - loop: true, - timeBased: false, - interval: 1, - currentFrame: 0, //当前帧的索引 Index of current frame - - /** - * @language=en - * Return the total amount of sprite animation frames. - * @returns {Uint} The total amount of frames. - */ - getNumFrames: function(){ - return this._frames ? this._frames.length : 0; - }, - - /** - * @language=en - * Add frame into sprite. - * @param {Object} frame Frames to add into. - * @param {Int} startIndex The index to start adding frame, if is not given, add at the end of sprite. - * @returns {Sprite} Sprite itself. - */ - addFrame: function(frame, startIndex){ - var start = startIndex != null ? startIndex : this._frames.length; - if(frame instanceof Array){ - for(var i = 0, len = frame.length; i < len; i++){ - this.setFrame(frame[i], start + i); - } - }else{ - this.setFrame(frame, start); - } - return this; - }, - - /** - * @language=en - * Set the frame on the given index. - * @param {Object} frame The frame data to set on that index. - * @param {Int} index Index of the frame to set. - * @returns {Sprite} Sprite itself. - */ - setFrame: function(frame, index){ - var frames = this._frames, - total = frames.length; - index = index < 0 ? 0 : index > total ? total : index; - frames[index] = frame; - if(frame.name) this._frameNames[frame.name] = frame; - if(index == 0 && !this.width || !this.height){ - this.width = frame.rect[2]; - this.height = frame.rect[3]; - } - return this; - }, - - /** - * @language=en - * Get the frame of given parameter from sprite. - * @param {Object} indexOrName The index or name of the frame. - * @returns {Object} The sprite object. - */ - getFrame: function(indexOrName){ - if(typeof indexOrName === 'number'){ - var frames = this._frames; - if(indexOrName < 0 || indexOrName >= frames.length) return null; - return frames[indexOrName]; - } - return this._frameNames[indexOrName]; - }, - - /** - * @language=en - * Get frame index from sprite. - * @param {Object} frameValue Index or name of the frame. - * @returns {Object} Sprite frame object. - */ - getFrameIndex: function(frameValue){ - var frames = this._frames, - total = frames.length, - index = -1; - if(typeof frameValue === 'number'){ - index = frameValue; - }else{ - var frame = typeof frameValue === 'string' ? this._frameNames[frameValue] : frameValue; - if(frame){ - for(var i = 0; i < total; i++){ - if(frame === frames[i]){ - index = i; - break; - } - } - } - } - return index; - }, - - /** - * @language=en - * Play sprite. - * @returns {Sprite} The Sprite object. - */ - play: function(){ - this.paused = false; - return this; - }, - - /** - * @language=en - * Pause playing sprite. - * @returns {Sprite} The Sprite object. - */ - stop: function(){ - this.paused = true; - return this; - }, - - /** - * @language=en - * Jump to an assigned frame. - * @param {Object} indexOrName Index or name of an frame to jump to. - * @param {Boolean} pause Does pause after jumping to the new index. - * @returns {Sprite} The Sprite object. - */ - goto: function(indexOrName, pause){ - var total = this._frames.length, - index = this.getFrameIndex(indexOrName); - - this.currentFrame = index < 0 ? 0 : index >= total ? total - 1 : index; - this.paused = pause; - this._firstRender = true; - return this; - }, - - /** - * @language=en - * Render function. - * @private - */ - _render: function(renderer, delta){ - var lastFrameIndex = this.currentFrame, frameIndex; - - if(this._firstRender){ - frameIndex = lastFrameIndex; - this._firstRender = false; - }else{ - frameIndex = this._nextFrame(delta); - } - - if(frameIndex != lastFrameIndex){ - this.currentFrame = frameIndex; - var callback = this._frames[frameIndex].callback; - callback && callback.call(this); - } - - //NOTE: it will be deprecated, don't use it. - if(this.onEnterFrame) this.onEnterFrame(frameIndex); - - this.drawable.init(this._frames[frameIndex]); - Sprite.superclass._render.call(this, renderer, delta); - }, - - /** - * @language=en - * @private - */ - _nextFrame: function(delta){ - var frames = this._frames, - total = frames.length, - frameIndex = this.currentFrame, - frame = frames[frameIndex], - duration = frame.duration || this.interval, - elapsed = this._frameElapsed; - - //calculate the current frame elapsed frames/time - var value = (frameIndex == 0 && !this.drawable) ? 0 : elapsed + (this.timeBased ? delta : 1); - elapsed = this._frameElapsed = value < duration ? value : 0; - - if(frame.stop || !this.loop && frameIndex >= total - 1){ - this.stop(); - } - - if(!this.paused && elapsed == 0){ - if(frame.next != null){ - //jump to the specified frame - frameIndex = this.getFrameIndex(frame.next); - }else if(frameIndex >= total - 1){ - //at the end of the frames, go back to first frame - frameIndex = 0; - }else if(this.drawable){ - //normal go forward to next frame - frameIndex++; - } - } - - return frameIndex; - }, - - /** - * @language=en - * Set a callback on an assigned frame. Every time assigned frame is played, invoke the callback function. If callback is empty, callback function will be removed. - * @param {Int|String} frame Index or name of the assigned frame. - * @param {Function} callback Callback function. - * @returns {Sprite} The Sprite object. - */ - setFrameCallback: function(frame, callback){ - frame = this.getFrame(frame); - if(frame) frame.callback = callback; - return this; - }, - - /** - * @language=en - * Callback function on when sprite enter a new frame. default value is null. Note: this function is obsolete, use addFrameCallback funciton instead. - * @type Function - * @deprecated - */ - onEnterFrame: null - -}); - -window.Hilo.Sprite = Sprite; -})(window); -/** - * Hilo 1.5.0 for standalone - * Copyright 2016 alibaba.com - * Licensed under the MIT License - */ -(function(window){ -if(!window.Hilo) window.Hilo = {}; -var Hilo = window.Hilo;var Class = window.Hilo.Class; -var View = window.Hilo.View; -var Drawable = window.Hilo.Drawable; - - -/** - * @language=en - * - *
- * demo: - *
- * var domView = new Hilo.DOMElement({
- *     element: Hilo.createElement('div', {
- *         style: {
- *             backgroundColor: '#004eff',
- *             position: 'absolute'
- *         }
- *     }),
- *     width: 100,
- *     height: 100,
- *     x: 50,
- *     y: 70
- * }).addTo(stage);
- * 
- * @name DOMElement - * @class DOMElement is a wrapper of dom element.(The DOMElement's parent must be stage) - * @augments View - * @param {Object} properties create Objects properties. Contains all writable properties in this class. Special properties include: - *
    - *
  • element - dom element to wrap, required!
  • - *
- * @module hilo/view/DOMElement - * @requires hilo/core/Hilo - * @requires hilo/core/Class - * @requires hilo/view/View - * @requires hilo/view/Drawable - */ -var DOMElement = Class.create(/** @lends DOMElement.prototype */{ - Extends: View, - constructor: function(properties){ - properties = properties || {}; - this.id = this.id || properties.id || Hilo.getUid("DOMElement"); - DOMElement.superclass.constructor.call(this, properties); - - this.drawable = new Drawable(); - var elem = this.drawable.domElement = properties.element || Hilo.createElement('div'); - elem.id = this.id; - - if(this.pointerEnabled && !elem.style.pointerEvents){ - elem.style.pointerEvents = 'visible'; - } - }, - - /** - * @language=en - * Overwrite render method. - * @private - */ - _render: function(renderer, delta){ - if(!this.onUpdate || this.onUpdate(delta) !== false){ - renderer.transform(this); - if(this.visible && this.alpha > 0){ - this.render(renderer, delta); - } - } - }, - - /** - * @language=en - * Overwrite render method. - * @private - */ - render: function(renderer, delta){ - if(renderer.renderType !== 'dom'){ - var canvas = renderer.canvas; - var stage = this.parent; - var domElementContainer = renderer._domElementContainer; - if(!renderer._domElementContainer){ - domElementContainer = renderer._domElementContainer = Hilo.createElement('div', { - style:{ - 'position':'absolute', - 'transform':'scale3d(' + stage.scaleX + ',' + stage.scaleY + ', 1)', - 'transformOrigin':'0 0', - 'zIndex':'1' - } - }); - canvas.parentNode.insertBefore(renderer._domElementContainer, canvas.nextSibling); - } - - var elem = this.drawable.domElement, depth = this.depth, - nextElement = domElementContainer.childNodes[0], nextDepth; - if(elem.parentNode) return; - - //draw dom element just after stage canvas - while(nextElement && nextElement.nodeType != 3){ - nextDepth = parseInt(nextElement.style.zIndex) || 0; - if(nextDepth <= 0 || nextDepth > depth){ - break; - } - nextElement = nextElement.nextSibling; - } - domElementContainer.insertBefore(this.drawable.domElement, nextElement); - }else{ - renderer.draw(this); - } - } -}); -window.Hilo.DOMElement = DOMElement; -})(window); -/** - * Hilo 1.5.0 for standalone - * Copyright 2016 alibaba.com - * Licensed under the MIT License - */ -(function(window){ -if(!window.Hilo) window.Hilo = {}; -var Hilo = window.Hilo;var Class = window.Hilo.Class; -var View = window.Hilo.View; -var CacheMixin = window.Hilo.CacheMixin; - - -/** - * @language=en - * - *
- * @class Graphics class contains a group of functions for creating vector graphics. - * @augments View - * @mixes CacheMixin - * @borrows CacheMixin#cache as #cache - * @borrows CacheMixin#updateCache as #updateCache - * @borrows CacheMixin#setCacheDirty as #setCacheDirty - * @param {Object} properties Properties parameters of the object to create. Contains all writable properties of this class. - * @module hilo/view/Graphics - * @requires hilo/core/Hilo - * @requires hilo/core/Class - * @requires hilo/view/View - * @requires hilo/view/CacheMixin - * @property {Number} lineWidth The thickness of lines in space units, default value is 1, readonly! - * @property {Number} lineAlpha The alpha value (transparency) of line, default value is 1, readonly! - * @property {String} lineCap The style of how every end point of line are drawn, value options: butt, round, square. default value is null, readonly! - * @property {String} lineJoin The joint style of two lines. value options: miter, round, bevel. default value is null, readonly! - * @property {Number} miterLimit The miter limit ratio in space units, works only when lineJoin value is miter. default value is 10, readonly! - * @property {String} strokeStyle The color or style to use for lines around shapes, default value is 0 (the black color), readonly! - * @property {String} fillStyle The color or style to use inside shapes, default value is 0 (the black color), readonly! - * @property {Number} fillAlpha The transparency of color or style inside shapes, default value is 0, readonly! - */ -var Graphics = (function(){ - -var canvas = document.createElement('canvas'); -var helpContext = canvas.getContext && canvas.getContext('2d'); - -return Class.create(/** @lends Graphics.prototype */{ - Extends: View, - Mixes:CacheMixin, - constructor: function(properties){ - properties = properties || {}; - this.id = this.id || properties.id || Hilo.getUid('Graphics'); - Graphics.superclass.constructor.call(this, properties); - - this._actions = []; - }, - - lineWidth: 1, - lineAlpha: 1, - lineCap: null, //'butt', 'round', 'square' - lineJoin: null, //'miter', 'round', 'bevel' - miterLimit: 10, - hasStroke: false, - strokeStyle: '0', - hasFill: false, - fillStyle: '0', - fillAlpha: 0, - - /** - * @language=en - * Set the lines style for drawing shapes. - * @param {Number} thickness The thickness of lines, default value is 1. - * @param {String} lineColor The CSS color value of lines, default value is 0 (the black color). - * @param {Number} lineAlpha The transparency of lines, default value is 1 (fully opaque). - * @param {String} lineCap The style of how every end point of line are drawn, value options: butt, round, square. default value is null. - * @param {String} lineJoin The joint style of two lines. value options: miter, round, bevel. default value is null. - * @param {Number} miterLimit The miter limit ratio in space units, works only when lineJoin value is miter. default value is 10. - * @returns {Graphics} The Graphics Object. - */ - lineStyle: function(thickness, lineColor, lineAlpha, lineCap, lineJoin, miterLimit){ - var me = this, addAction = me._addAction; - - addAction.call(me, ['lineWidth', (me.lineWidth = thickness || 1)]); - addAction.call(me, ['strokeStyle', (me.strokeStyle = lineColor || '0')]); - addAction.call(me, ['lineAlpha', (me.lineAlpha = lineAlpha || 1)]); - if(lineCap != undefined) addAction.call(me, ['lineCap', (me.lineCap = lineCap)]); - if(lineJoin != undefined) addAction.call(me, ['lineJoin', (me.lineJoin = lineJoin)]); - if(miterLimit != undefined) addAction.call(me, ['miterLimit', (me.miterLimit = miterLimit)]); - me.hasStroke = true; - return me; - }, - - /** - * 设置虚线样式 - * @param {Number[]} segments 一组描述交替绘制线段和间距(坐标空间单位)长度的数字 - * @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/setLineDash - */ - setLineDash: function(segments){ - return this._addAction(['setLineDash', segments]); - }, - - /** - * @language=en - * Set how to fill shapes and the transparency. - * @param {String} fill Filling style. this can be color, gradient or pattern. - * @param {Number} alpha Transparency. - * @returns {Graphics} The Graphics Object. - */ - beginFill: function(fill, alpha){ - var me = this, addAction = me._addAction; - - addAction.call(me, ['fillStyle', (me.fillStyle = fill)]); - addAction.call(me, ['fillAlpha', (me.fillAlpha = alpha || 1)]); - me.hasFill = true; - return me; - }, - - /** - * @language=en - * Apply and end lines-drawing and shapes-filling. - * @returns {Graphics} The Graphics Object. - */ - endFill: function(){ - var me = this, addAction = me._addAction; - - if(me.hasStroke) addAction.call(me, ['stroke']); - if(me.hasFill) addAction.call(me, ['fill']); - me.setCacheDirty(true); - return me; - }, - - /** - * @language=en - * Set linear gradient filling style to draw shapes. - * @param {Number} x0 The x-coordinate value of the linear gradient start point. - * @param {Number} y0 The y-coordinate value of the linear gradient start point. - * @param {Number} x1 The x-coordinate value of the linear gradient end point. - * @param {Number} y1 The y-coordinate value of the linear gradient end point. - * @param {Array} colors An array of CSS colors used in the linear gradient. - * @param {Array} ratios An array of position between start point and end point, should be one-to-one to colors in the colors array. each value range between 0.0 to 1.0. - * @returns {Graphics} The Graphics Object. - */ - beginLinearGradientFill: function(x0, y0, x1, y1, colors, ratios){ - var me = this, gradient = helpContext.createLinearGradient(x0, y0, x1, y1); - - for (var i = 0, len = colors.length; i < len; i++){ - gradient.addColorStop(ratios[i], colors[i]); - } - me.hasFill = true; - return me._addAction(['fillStyle', (me.fillStyle = gradient)]); - }, - - /** - * @language=en - * Set radial gradient filling style to draw shapes. - * @param {Number} x0 The x-coordinate value of the radial gradient start circle. - * @param {Number} y0 The y-coordinate value of the radial gradient start circle. - * @param {Number} r0 The diameter of the radial gradient start circle. - * @param {Number} x1 The x-coordinate value of the radial gradient end circle. - * @param {Number} y1 The y-coordinate value of the radial gradient end circle. - * @param {Number} r1 The radius of the radial gradient end circle. - * @param {Array} colors An array of CSS colors used in the radial gradient. - * @param {Array} ratios An array of position between start circle and end circle, should be one-to-one to colors in the colors array. each value range between 0.0 to 1.0. - * @returns {Graphics} The Graphics Object. - */ - beginRadialGradientFill: function(x0, y0, r0, x1, y1, r1, colors, ratios){ - var me = this, gradient = helpContext.createRadialGradient(x0, y0, r0, x1, y1, r1); - for (var i = 0, len = colors.length; i < len; i++) - { - gradient.addColorStop(ratios[i], colors[i]); - } - me.hasFill = true; - return me._addAction(['fillStyle', (me.fillStyle = gradient)]); - }, - - /** - * @language=en - * Begin an image filling pattern. - * @param {HTMLImageElement} image The Image to fill. - * @param {String} repetition The fill repetition style, can be one of valus:repeat, repeat-x, repeat-y, no-repeat. default valus is ''. - * @returns {Graphics} The Graphics Object. - */ - beginBitmapFill: function(image, repetition){ - var me = this, pattern = helpContext.createPattern(image, repetition || ''); - me.hasFill = true; - return me._addAction(['fillStyle', (me.fillStyle = pattern)]); - }, - - /** - * @language=en - * Begin a new path. - * @returns {Graphics} The Graphics Object. - */ - beginPath: function(){ - return this._addAction(['beginPath']); - }, - - /** - * @language=en - * Close current path. - * @returns {Graphics} The Graphics Object. - */ - closePath: function(){ - return this._addAction(['closePath']); - }, - - /** - * @language=en - * Move current drawing point to a new point on coordinate values (x, y). - * @param {Number} x The x-coordinate value. - * @param {Number} y The y-coordinate value. - * @returns {Graphics} The Graphics Object. - */ - moveTo: function(x, y){ - return this._addAction(['moveTo', x, y]); - }, - - /** - * @language=en - * Draw a line from current point to the point on the coordinate value (x, y). - * @param {Number} x The x-coordinate value. - * @param {Number} y The y-coordinate value. - * @returns {Graphics} The Graphics Object. - */ - lineTo: function(x, y){ - return this._addAction(['lineTo', x, y]); - }, - - /** - * @language=en - * Draw a quadratic Bézier curve from current point to the point on coordinate (x, y). - * @param {Number} cpx The x-coordinate value of the Bézier curve control point cp. - * @param {Number} cpy The y-coordinate value of the Bézier curve control point cp. - * @param {Number} x The x-coordinate value. - * @param {Number} y The y-coordinate value. - * @returns {Graphics} The Graphics Object. - */ - quadraticCurveTo: function(cpx, cpy, x, y){ - return this._addAction(['quadraticCurveTo', cpx, cpy, x, y]); - }, - - /** - * @language=en - * Draw a Bézier curve from current point to the point on coordinate (x, y). - * @param {Number} cp1x The x-coordinate value of the Bézier curve control point cp1. - * @param {Number} cp1y The y-coordinate value of the Bézier curve control point cp1. - * @param {Number} cp2x The x-coordinate value of the Bézier curve control point cp2. - * @param {Number} cp2y The y-coordinate value of the Bézier curve control point cp2. - * @param {Number} x The x-coordinate value. - * @param {Number} y The y-coordinate value. - * @returns {Graphics} The Graphics Object. - */ - bezierCurveTo: function(cp1x, cp1y, cp2x, cp2y, x, y){ - return this._addAction(['bezierCurveTo', cp1x, cp1y, cp2x, cp2y, x, y]); - }, - - /** - * @language=en - * Draw a rectangle. - * @param {Number} x The x-coordinate value. - * @param {Number} y The y-coordinate value. - * @param {Number} width The width of the rectangle. - * @param {Number} height The height of the rectangle. - * @returns {Graphics} The Graphics Object. - */ - drawRect: function(x, y, width, height){ - return this._addAction(['rect', x, y, width, height]); - }, - - /** - * @language=en - * Draw a complex rounded rectangle. - * @param {Number} x The x-coordinate value. - * @param {Number} y The y-coordinate value. - * @param {Number} width The width of rounded rectangle. - * @param {Number} height The height of rounded rectangle. - * @param {Number} cornerTL The size of the rounded corner on the top-left of the rounded rectangle. - * @param {Number} cornerTR The size of the rounded corner on the top-right of the rounded rectangle. - * @param {Number} cornerBR The size of the rounded corner on the bottom-left of the rounded rectangle. - * @param {Number} cornerBL The size of the rounded corner on the bottom-right of the rounded rectangle. - * @returns {Graphics} The Graphics Object. - */ - drawRoundRectComplex: function(x, y, width, height, cornerTL, cornerTR, cornerBR, cornerBL){ - var me = this, addAction = me._addAction; - addAction.call(me, ['moveTo', x + cornerTL, y]); - addAction.call(me, ['lineTo', x + width - cornerTR, y]); - addAction.call(me, ['arc', x + width - cornerTR, y + cornerTR, cornerTR, -Math.PI/2, 0, false]); - addAction.call(me, ['lineTo', x + width, y + height - cornerBR]); - addAction.call(me, ['arc', x + width - cornerBR, y + height - cornerBR, cornerBR, 0, Math.PI/2, false]); - addAction.call(me, ['lineTo', x + cornerBL, y + height]); - addAction.call(me, ['arc', x + cornerBL, y + height - cornerBL, cornerBL, Math.PI/2, Math.PI, false]); - addAction.call(me, ['lineTo', x, y + cornerTL]); - addAction.call(me, ['arc', x + cornerTL, y + cornerTL, cornerTL, Math.PI, Math.PI*3/2, false]); - return me; - }, - - /** - * @language=en - * Draw a rounded rectangle. - * @param {Number} x The x-coordinate value. - * @param {Number} y The y-coordinate value. - * @param {Number} width The width of rounded rectangle. - * @param {Number} height The height of rounded rectangle. - * @param {Number} cornerSize The size of all rounded corners. - * @returns {Graphics} The Graphics Object. - */ - drawRoundRect: function(x, y, width, height, cornerSize){ - return this.drawRoundRectComplex(x, y, width, height, cornerSize, cornerSize, cornerSize, cornerSize); - }, - - /** - * @language=en - * Draw a circle. - * @param {Number} x The x-coordinate value. - * @param {Number} y The y-coordinate value. - * @param {Number} radius The radius of the circle. - * @returns {Graphics} The Graphics Object. - */ - drawCircle: function(x, y, radius){ - return this._addAction(['arc', x + radius, y + radius, radius, 0, Math.PI * 2, 0]); - }, - - /** - * @language=en - * Draw an ellipse. - * @param {Number} x The x-coordinate value. - * @param {Number} y The y-coordinate value. - * @param {Number} width The width of the ellipse. - * @param {Number} height The height of the ellipse. - * @returns {Graphics} The Graphics Object. - */ - drawEllipse: function(x, y, width, height){ - var me = this; - if(width == height) return me.drawCircle(x, y, width); - - var addAction = me._addAction; - var w = width / 2, h = height / 2, C = 0.5522847498307933, cx = C * w, cy = C * h; - x = x + w; - y = y + h; - - addAction.call(me, ['moveTo', x + w, y]); - addAction.call(me, ['bezierCurveTo', x + w, y - cy, x + cx, y - h, x, y - h]); - addAction.call(me, ['bezierCurveTo', x - cx, y - h, x - w, y - cy, x - w, y]); - addAction.call(me, ['bezierCurveTo', x - w, y + cy, x - cx, y + h, x, y + h]); - addAction.call(me, ['bezierCurveTo', x + cx, y + h, x + w, y + cy, x + w, y]); - return me; - }, - - /** - * @language=en - * Draw a path from the SVG data given by parameters. Not support Arcs. - * Demo: - *

var path = 'M250 150 L150 350 L350 350 Z';

- *

var shape = new Hilo.Graphics({width:500, height:500});

- *

shape.drawSVGPath(path).beginFill('#0ff').endFill();

- * @param {String} pathData The SVG path data to draw. - * @returns {Graphics} The Graphics Object. - */ - drawSVGPath: function(pathData){ - var me = this, addAction = me._addAction, - path = pathData.replace(/,/g, ' ').replace(/-/g, ' -').split(/(?=[a-zA-Z])/); - addAction.call(me, ['beginPath']); - var currentPoint = {x:0, y:0}; - var lastControlPoint = {x:0, y:0}; - var lastCmd; - for(var i = 0, len = path.length; i < len; i++){ - var str = path[i]; - if(!str.length){ - continue; - } - var realCmd = str[0]; - var cmd = realCmd.toUpperCase(); - var p = this._getSVGParams(str); - var useRelative = cmd !== realCmd; - - switch(cmd){ - case 'M': - if(useRelative){ - this._convertToAbsolute(currentPoint, p); - } - addAction.call(me, ['moveTo', p[0], p[1]]); - this._setCurrentPoint(currentPoint, p[0], p[1]); - break; - case 'L': - if(useRelative){ - this._convertToAbsolute(currentPoint, p); - } - addAction.call(me, ['lineTo', p[0], p[1]]); - this._setCurrentPoint(currentPoint, p[0], p[1]); - break; - case 'H': - if(useRelative){ - p[0] += currentPoint.x; - } - addAction.call(me, ['lineTo', p[0], currentPoint.y]); - currentPoint.x = p[0]; - break; - case 'V': - if(useRelative){ - p[0] += currentPoint.y; - } - addAction.call(me, ['lineTo', currentPoint.x, p[0]]); - currentPoint.y = p[0]; - break; - case 'Z': - addAction.call(me, ['closePath']); - break; - case 'C': - if(useRelative){ - this._convertToAbsolute(currentPoint, p); - } - addAction.call(me, ['bezierCurveTo', p[0], p[1], p[2], p[3], p[4], p[5]]); - lastControlPoint.x = p[2]; - lastControlPoint.y = p[3]; - this._setCurrentPoint(currentPoint, p[4], p[5]); - break; - case 'S': - if(useRelative){ - this._convertToAbsolute(currentPoint, p); - } - if(lastCmd === 'C' || lastCmd === 'S'){ - controlPoint = this._getReflectionPoint(currentPoint, lastControlPoint); - } - else{ - controlPoint = currentPoint; - } - addAction.call(me, ['bezierCurveTo', controlPoint.x, controlPoint.y, p[0], p[1], p[2], p[3]]); - lastControlPoint.x = p[0]; - lastControlPoint.y = p[1]; - this._setCurrentPoint(currentPoint, p[2], p[3]); - break; - case 'Q': - if(useRelative){ - this._convertToAbsolute(currentPoint, p); - } - addAction.call(me, ['quadraticCurveTo', p[0], p[1], p[2], p[3]]); - lastControlPoint.x = p[0]; - lastControlPoint.y = p[1]; - this._setCurrentPoint(currentPoint, p[2], p[3]); - break; - case 'T': - if(useRelative){ - this._convertToAbsolute(currentPoint, p); - } - var controlPoint; - if(lastCmd === 'Q' || lastCmd === 'T'){ - controlPoint = this._getReflectionPoint(currentPoint, lastControlPoint); - } - else{ - controlPoint = currentPoint; - } - addAction.call(me, ['quadraticCurveTo', controlPoint.x, controlPoint.y, p[0], p[1]]); - lastControlPoint = controlPoint; - this._setCurrentPoint(currentPoint, p[0], p[1]); - break; - } - lastCmd = cmd; - - } - return me; - }, - _getSVGParams:function(str){ - var p = str.substring(1).replace(/[\s]+$|^[\s]+/g, '').split(/[\s]+/); - if(p[0].length == 0) { - p.shift(); - } - for(var i = 0, l = p.length;i < l;i ++){ - p[i] = parseFloat(p[i]); - } - return p; - }, - _convertToAbsolute:function(currentPoint, data){ - for(var i = 0, l = data.length;i < l;i ++){ - if(i%2 === 0){ - data[i] += currentPoint.x; - } - else{ - data[i] += currentPoint.y; - } - } - }, - _setCurrentPoint:function(currentPoint, x, y){ - currentPoint.x = x; - currentPoint.y = y; - }, - _getReflectionPoint:function(centerPoint, point){ - return { - x:centerPoint.x * 2 - point.x, - y:centerPoint.y * 2 - point.y - }; - }, - - /** - * @language=en - * Apply all draw actions. private function. - * @private - */ - _draw: function(context){ - var me = this, actions = me._actions, len = actions.length, i; - - context.beginPath(); - for(i = 0; i < len; i++){ - var action = actions[i], - f = action[0], - args = action.length > 1 ? action.slice(1) : null; - - if(typeof(context[f]) == 'function') context[f].apply(context, args); - else context[f] = action[1]; - } - }, - - /** - * @language=en - * Overwrite render function. - * @private - */ - render: function(renderer, delta){ - var me = this; - if(renderer.renderType === 'canvas'){ - me._draw(renderer.context); - }else{ - me.cache(); - renderer.draw(me); - } - }, - - /** - * @language=en - * Clear all draw actions and reset to the initial state. - * @returns {Graphics} The Graphics Object. - */ - clear: function(){ - var me = this; - - me._actions.length = 0; - me.lineWidth = 1; - me.lineAlpha = 1; - me.lineCap = null; - me.lineJoin = null; - me.miterLimit = 10; - me.hasStroke = false; - me.strokeStyle = '0'; - me.hasFill = false; - me.fillStyle = '0'; - me.fillAlpha = 1; - - me.setCacheDirty(true); - return me; - }, - - /** - * @language=en - * Add a draw action, this is a private function. - * @private - */ - _addAction: function(action){ - var me = this; - me._actions.push(action); - return me; - } - -}); - -})(); - -window.Hilo.Graphics = Graphics; -})(window); -/** - * Hilo 1.5.0 for standalone - * Copyright 2016 alibaba.com - * Licensed under the MIT License - */ -(function(window){ -if(!window.Hilo) window.Hilo = {}; -var Class = window.Hilo.Class; -var Hilo = window.Hilo;var View = window.Hilo.View; -var CacheMixin = window.Hilo.CacheMixin; - - -/** - * @language=en - * - *
- * @class Text class provide basic text-display function, use DOMElement for complex text-display. - * @augments View - * @mixes CacheMixin - * @borrows CacheMixin#cache as #cache - * @borrows CacheMixin#updateCache as #updateCache - * @borrows CacheMixin#setCacheDirty as #setCacheDirty - * @param {Object} properties Properties parameters for the object. Includes all writable properties. - * @module hilo/view/Text - * @requires hilo/core/Class - * @requires hilo/core/Hilo - * @requires hilo/view/View - * @requires hilo/view/CacheMixin - * @property {String} text Text to display. - * @property {String} color Color of the text. - * @property {String} textAlign Horizontal alignment way of the text. May be one of the following value:'start', 'end', 'left', 'right', and 'center'. Note:Need to specify the width property of the text to take effect - * @property {String} textVAlign Vertical alignment way of the text. May be one of the following value:'top', 'middle', 'bottom'. Note:Need to specify the height property of the text to take effect. - * @property {Boolean} outline Draw the outline of the text or fill the text. - * @property {Number} lineSpacing The spacing between lines. Measured in px, default value is 0. - * @property {Number} maxWidth The max length of the text, default value is 200. - * @property {String} font Text's CSS font style, readonly! Use setFont function to set text font. - * @property {Number} textWidth Width of the text, readonly! Works only on canvas mode. - * @property {Number} textHeight Height of the text, readonly! Works only on canvas mode. - */ -var Text = Class.create(/** @lends Text.prototype */{ - Extends: View, - Mixes:CacheMixin, - constructor: function(properties){ - properties = properties || {}; - this.id = this.id || properties.id || Hilo.getUid('Text'); - Text.superclass.constructor.call(this, properties); - - // if(!properties.width) this.width = 200; //default width - if(!properties.font) this.font = '12px arial'; //default font style - this._fontHeight = Text.measureFontHeight(this.font); - }, - - text: '', - color: '#000', - textAlign: null, - textVAlign: null, - outline: false, - lineSpacing: 0, - maxWidth: 200, - font: null, //ready-only - textWidth: 0, //read-only - textHeight: 0, //read-only - - /** - * @language=en - * Set text CSS font style. - * @param {String} font Text CSS font style to set. - * @returns {Text} the Text object, chained call supported. - */ - setFont: function(font){ - var me = this; - if(me.font !== font){ - me.font = font; - me._fontHeight = Text.measureFontHeight(font); - } - - return me; - }, - - /** - * @language=en - * Overwrite render function. - * @private - */ - render: function(renderer, delta){ - var me = this; - - if(renderer.renderType === 'canvas'){ - if(this.drawable){ - renderer.draw(me); - } - else{ - me._draw(renderer.context); - } - } - else if(renderer.renderType === 'dom'){ - var drawable = me.drawable; - var domElement = drawable.domElement; - var style = domElement.style; - - style.font = me.font; - style.textAlign = me.textAlign; - style.color = me.color; - style.width = me.width + 'px'; - style.height = me.height + 'px'; - style.lineHeight = (me._fontHeight + me.lineSpacing) + 'px'; - - domElement.innerHTML = me.text; - renderer.draw(this); - } - else{ - //TODO:自动更新cache TODO:auto update cache - me.cache(); - renderer.draw(me); - } - }, - - /** - * @language=en - * Draw text under the assigned render context. - * @private - */ - _draw: function(context){ - var me = this, text = me.text.toString(); - if(!text) return; - - //set drawing style - context.font = me.font; - context.textAlign = me.textAlign; - context.textBaseline = 'top'; - - //find and draw all explicit lines - var lines = text.split(/\r\n|\r|\n|/); - var width = 0, height = 0; - var lineHeight = me._fontHeight + me.lineSpacing; - var i, line, w, len, wlen; - var drawLines = []; - - for(i = 0, len = lines.length; i < len; i++){ - line = lines[i]; - w = context.measureText(line).width; - - //check if the line need to split - if(w <= me.maxWidth){ - drawLines.push({text:line, y:height}); - // me._drawTextLine(context, line, height); - if(width < w) width = w; - height += lineHeight; - continue; - } - - var str = '', oldWidth = 0, newWidth, j, word; - - for(j = 0, wlen = line.length; j < wlen; j++){ - word = line[j]; - newWidth = context.measureText(str + word).width; - - if(newWidth > me.maxWidth){ - drawLines.push({text:str, y:height}); - // me._drawTextLine(context, str, height); - if(width < oldWidth) width = oldWidth; - height += lineHeight; - str = word; - }else{ - oldWidth = newWidth; - str += word; - } - - if(j == wlen - 1){ - drawLines.push({text:str, y:height}); - // me._drawTextLine(context, str, height); - if(str !== word && width < newWidth) width = newWidth; - height += lineHeight; - } - } - } - - me.textWidth = width; - me.textHeight = height; - if(!me.width) me.width = width; - if(!me.height) me.height = height; - - //vertical alignment - var startY = 0; - switch(me.textVAlign){ - case 'middle': - startY = me.height - me.textHeight >> 1; - break; - case 'bottom': - startY = me.height - me.textHeight; - break; - } - - //draw background - var bg = me.background; - if(bg){ - context.fillStyle = bg; - context.fillRect(0, 0, me.width, me.height); - } - - if(me.outline) context.strokeStyle = me.color; - else context.fillStyle = me.color; - - //draw text lines - for(i = 0; i < drawLines.length; i++){ - line = drawLines[i]; - me._drawTextLine(context, line.text, startY + line.y); - } - }, - - /** - * @language=en - * Draw a line of text under the assigned render context. - * @private - */ - _drawTextLine: function(context, text, y){ - var me = this, x = 0, width = me.width; - - switch(me.textAlign){ - case 'center': - x = width >> 1; - break; - case 'right': - case 'end': - x = width; - break; - } - - if(me.outline) context.strokeText(text, x, y); - else context.fillText(text, x, y); - }, - - Statics: /** @lends Text */{ - /** - * @language=en - * Measure the line height of the assigned text font style. - * @param {String} font Font style to measure. - * @return {Number} Return line height of the assigned font style. - */ - measureFontHeight: function(font){ - var docElement = document.documentElement, fontHeight; - var elem = Hilo.createElement('div', {style:{font:font, position:'absolute'}, innerHTML:'M'}); - - docElement.appendChild(elem); - fontHeight = elem.offsetHeight; - docElement.removeChild(elem); - return fontHeight; - } - } - -}); - -window.Hilo.Text = Text; -})(window); -/** - * Hilo 1.5.0 for standalone - * Copyright 2016 alibaba.com - * Licensed under the MIT License - */ -(function(window){ -if(!window.Hilo) window.Hilo = {}; -var Class = window.Hilo.Class; -var Hilo = window.Hilo;var Container = window.Hilo.Container; -var Bitmap = window.Hilo.Bitmap; - - -/** - * @language=en - * - *
- * @class BitmapText support bitmap text function ,but only support single-line text - * @augments Container - * @param {Object} properties the options of create Instance.It can contains all writable property - * @module hilo/view/BitmapText - * @requires hilo/core/Class - * @requires hilo/core/Hilo - * @requires hilo/view/Container - * @requires hilo/view/Bitmap - * @property {Object} glyphs font glyph set of bitmap. format:{letter:{image:img, rect:[0,0,100,100]}} - * @property {Number} letterSpacing spacing of letter. default:0 - * @property {String} text content of bitmap text. Not writable,set this value by 'setText' - * @property {String} textAlign property values:left、center、right, default:left,Not writable,set this property by 'setTextAlign' - */ -var BitmapText = Class.create(/** @lends BitmapText.prototype */{ - Extends: Container, - constructor: function(properties){ - properties = properties || {}; - this.id = this.id || properties.id || Hilo.getUid('BitmapText'); - BitmapText.superclass.constructor.call(this, properties); - - var text = properties.text + ''; - if(text){ - this.text = ''; - this.setText(text); - } - - this.pointerChildren = false; //disable user events for single letters - }, - - glyphs: null, - letterSpacing: 0, - text: '', - textAlign:'left', - - /** - * @language=en - * set the content of bitmap text - * @param {String} text content - * @returns {BitmapText} BitmapText Instance,support chained calls - */ - setText: function(text){ - var me = this, str = text.toString(), len = str.length; - if(me.text == str) return; - me.text = str; - - var i, charStr, charGlyph, charObj, width = 0, height = 0, left = 0; - for(i = 0; i < len; i++){ - charStr = str.charAt(i); - charGlyph = me.glyphs[charStr]; - if(charGlyph){ - left = width + (width > 0 ? me.letterSpacing : 0); - if(me.children[i]){ - charObj = me.children[i]; - charObj.setImage(charGlyph.image, charGlyph.rect); - } - else{ - charObj = me._createBitmap(charGlyph); - me.addChild(charObj); - } - charObj.x = left; - width = left + charGlyph.rect[2]; - height = Math.max(height, charGlyph.rect[3]); - } - } - - for(i = me.children.length - 1;i >= len;i --){ - me._releaseBitmap(me.children[i]); - me.children[i].removeFromParent(); - } - - me.width = width; - me.height = height; - this.setTextAlign(); - return me; - }, - _createBitmap:function(cfg){ - var bmp; - if(BitmapText._pool.length){ - bmp = BitmapText._pool.pop(); - bmp.setImage(cfg.image, cfg.rect); - } - else{ - bmp = new Bitmap({ - image:cfg.image, - rect:cfg.rect - }); - } - return bmp; - }, - _releaseBitmap:function(bmp){ - BitmapText._pool.push(bmp); - }, - - /** - * @language=en - * set the textAlign of text。 - * @param textAlign value of textAlign:left、center、right - * @returns {BitmapText} itmapText Instance,support chained calls - */ - setTextAlign:function(textAlign){ - this.textAlign = textAlign||this.textAlign; - switch(this.textAlign){ - case "center": - this.pivotX = this.width * .5; - break; - case "right": - this.pivotX = this.width; - break; - case "left": - /* falls through */ - default: - this.pivotX = 0; - break; - } - return this; - }, - - /** - * @language=en - * detect whether can display the string by the currently assigned font provided - * @param {String} str to detect string - * @returns {Boolean} whether can display the string - */ - hasGlyphs: function(str){ - var glyphs = this.glyphs; - if(!glyphs) return false; - - str = str.toString(); - var len = str.length, i; - for(i = 0; i < len; i++){ - if(!glyphs[str.charAt(i)]) return false; - } - return true; - }, - - Statics:/** @lends BitmapText */{ - _pool:[], - /** - * @language=en - * easy way to generate a collection of glyphs - * @static - * @param {String} text character text. - * @param {Image} image character image. - * @param {Number} col default:the length of string - * @param {Number} row default:1 - * @returns {BitmapText} BitmapText对象本身。链式调用支持。 - */ - createGlyphs:function(text, image, col, row){ - var str = text.toString(); - col = col||str.length; - row = row||1; - var w = image.width/col; - var h = image.height/row; - var glyphs = {}; - for(var i = 0, l = text.length;i < l;i ++){ - var charStr = str.charAt(i); - glyphs[charStr] = { - image:image, - rect:[w * (i % col), h * Math.floor(i / col), w, h] - }; - } - return glyphs; - } - } - -}); - -window.Hilo.BitmapText = BitmapText; -})(window); -/** - * Hilo 1.5.0 for standalone - * Copyright 2016 alibaba.com - * Licensed under the MIT License - */ -(function(window){ -if(!window.Hilo) window.Hilo = {}; -var Hilo = window.Hilo;var Class = window.Hilo.Class; -var View = window.Hilo.View; -var Drawable = window.Hilo.Drawable; -var util = window.Hilo.util; - - -/** - * @language=en - * - *
- * demo: - *
- * var btn = new Hilo.Button({
- *     image: buttonImage,
- *     upState: {rect:[0, 0, 64, 64]},
- *     overState: {rect:[64, 0, 64, 64]},
- *     downState: {rect:[128, 0, 64, 64]},
- *     disabledState: {rect:[192, 0, 64, 64]}
- * });
- * 
- * @class Button class is a simple button class, contains four kinds of state: 'up', 'over', 'down', 'disabled' - * @augments View - * @param {Object} properties create object properties. Contains all writable properties. Also contains: - *
    - *
  • image - the image element that button image is in
  • - *
- * @module hilo/view/Button - * @requires hilo/core/Hilo - * @requires hilo/core/Class - * @requires hilo/view/View - * @requires hilo/view/Drawable - * @requires hilo/util/util - * @property {Object} upState The property of button 'up' state or collections of its drawable properties. - * @property {Object} overState The property of button 'over' state or collections of its drawable properties. - * @property {Object} downState The property of button 'down' state or collections of its drawable properties. - * @property {Object} disabledState The property of button 'disabled' state or collections of its drawable properties. - * @property {String} state the state name of button, could be one of Button.UP|OVER|DOWN|DISABLED, readonly! - * @property {Boolean} enabled Is button enabled. default value is true, readonly! - * @property {Boolean} useHandCursor If true, cursor over the button will become a pointer cursor, default value is true. - */ - var Button = Class.create(/** @lends Button.prototype */{ - Extends: View, - constructor: function(properties){ - properties = properties || {}; - this.id = this.id || properties.id || Hilo.getUid("Button"); - Button.superclass.constructor.call(this, properties); - - this.drawable = new Drawable(properties); - this.setState(Button.UP); - }, - - upState: null, - overState: null, - downState: null, - disabledState: null, - - state: null, - enabled: true, - useHandCursor: true, - - /** - * @language=en - * Set whether the button is enabled. - * @param {Boolean} enabled Show whether the button is enabled. - * @returns {Button} Return the button itself. - */ - setEnabled: function(enabled){ - if(this.enabled != enabled){ - if(!enabled){ - this.setState(Button.DISABLED); - }else{ - this.setState(Button.UP); - } - } - return this; - }, - - /** - * @language=en - * Set the state of the button. Invoke inside the Button and may not be used. - * @param {String} state New state of the button. - * @returns {Button} Return the button itself. - */ - setState: function(state){ - if(this.state !== state){ - this.state = state; - this.pointerEnabled = this.enabled = state !== Button.DISABLED; - - var stateObj; - switch(state){ - case Button.UP: - stateObj = this.upState; - break; - case Button.OVER: - stateObj = this.overState; - break; - case Button.DOWN: - stateObj = this.downState; - break; - case Button.DISABLED: - stateObj = this.disabledState; - break; - } - - if(stateObj){ - this.drawable.init(stateObj); - util.copy(this, stateObj, true); - } - } - - return this; - }, - - /** - * @language=en - * overwrite - * @private - */ - fire: function(type, detail){ - if(!this.enabled) return; - - var evtType = typeof type === 'string' ? type : type.type; - switch(evtType){ - case 'mousedown': - case 'touchstart': - case 'touchmove': - this.setState(Button.DOWN); - break; - case "mouseover": - this.setState(Button.OVER); - break; - case 'mouseup': - if(this.overState) this.setState(Button.OVER); - else if(this.upState) this.setState(Button.UP); - break; - case 'touchend': - case 'touchout': - case 'mouseout': - this.setState(Button.UP); - break; - } - - return Button.superclass.fire.call(this, type, detail); - }, - - Statics: /** @lends Button */ { - /** - * @language=en - * Statics value of Button's 'up' state. - * @type String - */ - UP: 'up', - /** - * @language=en - * Statics value of Button's 'over' state. - * @type String - */ - OVER: 'over', - /** - * @language=en - * Statics value of Button's 'down' state. - * @type String - */ - DOWN: 'down', - /** - * @language=en - * Statics value of Button's 'disabled' state. - * @type String - */ - DISABLED: 'disabled' - } - }); -window.Hilo.Button = Button; -})(window); -/** - * Hilo 1.5.0 for standalone - * Copyright 2016 alibaba.com - * Licensed under the MIT License - */ -(function(window){ -if(!window.Hilo) window.Hilo = {}; -var Class = window.Hilo.Class; - - -/** - * @language=en - * @class TextureAtlas纹理集是将许多小的纹理图片整合到一起的一张大图。这个类可根据一个纹理集数据读取纹理小图、精灵动画等。 - * @param {Object} atlasData 纹理集数据。它可包含如下数据: - *
    - *
  • image - 纹理集图片。必需。
  • - *
  • width - 纹理集图片宽度。若frames数据为Object时,此属性必需。
  • - *
  • height - 纹理集图片高度。若frames数据为Object时,此属性必需。
  • - *
  • frames - 纹理集帧数据,可以是Array或Object。必需。 - *
      - *
    • 若为Array,则每项均为一个纹理图片帧数据,如:[[0, 0, 50, 50], [0, 50, 50, 50]。
    • - *
    • 若为Object,则需包含frameWidth(帧宽)、frameHeight(帧高)、numFrames(帧数) 属性。
    • - *
    - *
  • - *
  • sprites - 纹理集精灵动画定义,其每个值均定义一个精灵。为Object对象。可选。 - *
      - *
    • 若为Number,即此精灵只包含一帧,此帧为帧数据中索引为当前值的帧。如:sprites:{'foo':1}。
    • - *
    • 若为Array,则每项均为一个帧的索引值。如:sprites:{'foo':[0, 1, 2, 3]}。
    • - *
    • 若为Object,则需包含from(起始帧索引值)、to(末帧索引值) 属性。
    • - *
    - *
  • - *
- * @module hilo/util/TextureAtlas - * @requires hilo/core/Class - */ -var TextureAtlas = (function(){ - -return Class.create(/** @lends TextureAtlas.prototype */{ - constructor: function(atlasData){ - this._frames = parseTextureFrames(atlasData); - this._sprites = parseTextureSprites(atlasData, this._frames); - }, - - _frames: null, - _sprites: null, - - /** - * @language=en - * 获取指定索引位置index的帧数据。 - * @param {Int} index 要获取帧的索引位置。 - * @returns {Object} 帧数据。 - */ - getFrame: function(index){ - var frames = this._frames; - return frames && frames[index]; - }, - - /** - * @language=en - * 获取指定id的精灵数据。 - * @param {String} id 要获取精灵的id。 - * @returns {Object} 精灵数据。 - */ - getSprite: function(id){ - var sprites = this._sprites; - return sprites && sprites[id]; - }, - - Statics: /** @lends TextureAtlas */ { - /** - * @language=en - * Shorthand method to create spirte frames - * @param {String|Array} name Name of one animation|a group of animation - * @param {String} frames Frames message, eg:"0-5" means frame 0 to frame 5. - * @param {Number} w The width of each frame. - * @param {Number} h The height of each frame. - * @param {Boolean} loop Is play in loop. - * @param {Number} duration The time between each frame. default value is 1 (Frame), but if timeBased is true, default value will be duration(milli-second). - * @example - * //demo1 make one animation - * createSpriteFrames("walk", "0-5,8,9", meImg, 55, 88, true, 1); - * //demo2 make a group of animation - * createSpriteFrames([ - * ["walk", "0-5,8,9", meImg, 55, 88, true, 1], - * ["jump", "0-5", meImg, 55, 88, false, 1] - * ]); - */ - createSpriteFrames:function(name, frames, img, w, h, loop, duration){ - var i, l; - if(Object.prototype.toString.call(name) === "[object Array]"){ - var res = []; - for(i = 0, l = name.length;i < l;i ++){ - res = res.concat(this.createSpriteFrames.apply(this, name[i])); - } - return res; - } - else{ - if(typeof(frames) === "string"){ - var all = frames.split(","); - frames = []; - for(var j = 0, jl = all.length;j < jl;j ++){ - var temp = all[j].split("-"); - if(temp.length == 1){ - frames.push(parseInt(temp[0])); - } - else{ - for(i = parseInt(temp[0]), l = parseInt(temp[1]);i <= l;i ++){ - frames.push(i); - } - } - } - } - - var col = Math.floor(img.width/w); - for(i = 0;i < frames.length;i ++){ - var n = frames[i]; - frames[i] = { - rect:[w*(n%col), h*Math.floor(n/col), w, h], - image:img, - duration:duration - }; - } - frames[0].name = name; - if(loop){ - frames[frames.length-1].next = name; - } - else{ - frames[frames.length-1].stop = true; - } - return frames; - } - } - } -}); - -/** - * @language=en - * Parse texture frames - * @private - */ -function parseTextureFrames(atlasData){ - var i, len; - var frameData = atlasData.frames; - if(!frameData) return null; - - var frames = [], obj; - - if(frameData instanceof Array){ //frames by array - for(i = 0, len = frameData.length; i < len; i++){ - obj = frameData[i]; - frames[i] = { - image: atlasData.image, - rect: obj - }; - } - }else{ //frames by object - var frameWidth = frameData.frameWidth; - var frameHeight = frameData.frameHeight; - var cols = atlasData.width / frameWidth | 0; - var rows = atlasData.height / frameHeight | 0; - var numFrames = frameData.numFrames || cols * rows; - for(i = 0; i < numFrames; i++){ - frames[i] = { - image: atlasData.image, - rect: [i%cols*frameWidth, (i/cols|0)*frameHeight, frameWidth, frameHeight] - }; - } - } - - return frames; -} - -/** - * @language=en - * Parse texture sprites - * @private - */ -function parseTextureSprites(atlasData, frames){ - var i, len; - var spriteData = atlasData.sprites; - if(!spriteData) return null; - - var sprites = {}, sprite, spriteFrames, spriteFrame; - - for(var s in spriteData){ - sprite = spriteData[s]; - if(isNumber(sprite)){ //single frame - spriteFrames = translateSpriteFrame(frames[sprite]); - }else if(sprite instanceof Array){ //frames by array - spriteFrames = []; - for(i = 0, len = sprite.length; i < len; i++){ - var spriteObj = sprite[i], frameObj; - if(isNumber(spriteObj)){ - spriteFrame = translateSpriteFrame(frames[spriteObj]); - }else{ - frameObj = spriteObj.rect; - if(isNumber(frameObj)) frameObj = frames[spriteObj.rect]; - spriteFrame = translateSpriteFrame(frameObj, spriteObj); - } - spriteFrames[i] = spriteFrame; - } - }else{ //frames by object - spriteFrames = []; - for(i = sprite.from; i <= sprite.to; i++){ - spriteFrames[i - sprite.from] = translateSpriteFrame(frames[i], sprite[i]); - } - } - sprites[s] = spriteFrames; - } - - return sprites; -} - -function translateSpriteFrame(frameObj, spriteObj){ - var spriteFrame = { - image: frameObj.image, - rect: frameObj.rect - }; - - if(spriteObj){ - spriteFrame.name = spriteObj.name || null; - spriteFrame.duration = spriteObj.duration || 0; - spriteFrame.stop = !!spriteObj.stop; - spriteFrame.next = spriteObj.next || null; - } - - return spriteFrame; -} - -function isNumber(value){ - return typeof value === 'number'; -} - -})(); -window.Hilo.TextureAtlas = TextureAtlas; -})(window); -/** - * Hilo 1.5.0 for standalone - * Copyright 2016 alibaba.com - * Licensed under the MIT License - */ -(function(window){ -if(!window.Hilo) window.Hilo = {}; -var Class = window.Hilo.Class; -var browser = window.Hilo.browser; - - -/** - * @language=en - * @class Ticker is a Timer. It can run the code at specified framerate. - * @param {Number} fps The fps of ticker.Default is 60. - * @module hilo/util/Ticker - * @requires hilo/core/Class - * @requires hilo/util/browser - */ -var Ticker = Class.create(/** @lends Ticker.prototype */{ - constructor: function(fps){ - this._targetFPS = fps || 60; - this._interval = 1000 / this._targetFPS; - this._tickers = []; - }, - - _paused: false, - _targetFPS: 0, - _interval: 0, - _intervalId: null, - _tickers: null, - _lastTime: 0, - _tickCount: 0, - _tickTime: 0, - _measuredFPS: 0, - - /** - * @language=en - * Start the ticker. - * @param {Boolean} userRAF Whether or not use requestAnimationFrame, default is true. - */ - start: function(useRAF){ - if(useRAF === undefined){ - useRAF = true; - } - - if(this._intervalId) return; - this._lastTime = +new Date(); - - var self = this, interval = this._interval, - raf = window.requestAnimationFrame || - window[browser.jsVendor + 'RequestAnimationFrame']; - - var runLoop; - if(useRAF && raf && interval < 17){ - this._useRAF = true; - runLoop = function(){ - self._intervalId = raf(runLoop); - self._tick(); - }; - }else{ - runLoop = function(){ - self._intervalId = setTimeout(runLoop, interval); - self._tick(); - }; - } - - this._paused = false; - runLoop(); - }, - - /** - * @language=en - * Stop the ticker. - */ - stop: function(){ - if(this._useRAF){ - var cancelRAF = window.cancelAnimationFrame || - window[browser.jsVendor + 'CancelAnimationFrame']; - cancelRAF(this._intervalId); - } - else{ - clearTimeout(this._intervalId); - } - this._intervalId = null; - this._lastTime = 0; - this._paused = true; - }, - - /** - * @language=en - * Pause the ticker. - */ - pause: function(){ - this._paused = true; - }, - - /** - * @language=en - * Resume the ticker. - */ - resume: function(){ - this._paused = false; - }, - - /** - * @private - */ - _tick: function(){ - if(this._paused) return; - var startTime = +new Date(), - deltaTime = startTime - this._lastTime, - tickers = this._tickers; - - //calculates the real fps - if(++this._tickCount >= this._targetFPS){ - this._measuredFPS = 1000 / (this._tickTime / this._tickCount) + 0.5 >> 0; - this._tickCount = 0; - this._tickTime = 0; - }else{ - this._tickTime += startTime - this._lastTime; - } - this._lastTime = startTime; - - var tickersCopy = tickers.slice(0); - for(var i = 0, len = tickersCopy.length; i < len; i++){ - tickersCopy[i].tick(deltaTime); - } - }, - - /** - * @language=en - * Get the fps. - */ - getMeasuredFPS: function(){ - return Math.min(this._measuredFPS, this._targetFPS); - }, - - /** - * @language=en - * Add tickObject. The tickObject must implement the tick method. - * @param {Object} tickObject The tickObject to add.It must implement the tick method. - */ - addTick: function(tickObject){ - if(!tickObject || typeof(tickObject.tick) != 'function'){ - throw new Error('Ticker: The tick object must implement the tick method.'); - } - this._tickers.push(tickObject); - }, - - /** - * @language=en - * Remove the tickObject - * @param {Object} tickObject The tickObject to remove. - */ - removeTick: function(tickObject){ - var tickers = this._tickers, - index = tickers.indexOf(tickObject); - if(index >= 0){ - tickers.splice(index, 1); - } - }, - /** - * 下次tick时回调 - * @param {Function} callback - * @return {tickObj} - */ - nextTick:function(callback){ - var that = this; - var tickObj = { - tick:function(dt){ - that.removeTick(tickObj); - callback(); - } - }; - - that.addTick(tickObj); - return tickObj; - }, - /** - * 延迟指定的时间后调用回调, 类似setTimeout - * @param {Function} callback - * @param {Number} duration 延迟的毫秒数 - * @return {tickObj} - */ - timeout:function(callback, duration){ - var that = this; - var targetTime = new Date().getTime() + duration; - var tickObj = { - tick:function(){ - var nowTime = new Date().getTime(); - var dt = nowTime - targetTime; - if(dt >= 0){ - that.removeTick(tickObj); - callback(); - } - } - }; - that.addTick(tickObj); - return tickObj; - }, - /** - * 指定的时间周期来调用函数, 类似setInterval - * @param {Function} callback - * @param {Number} duration 时间周期,单位毫秒 - * @return {tickObj} - */ - interval:function(callback, duration){ - var that = this; - var targetTime = new Date().getTime() + duration; - var tickObj = { - tick:function(){ - var nowTime = new Date().getTime(); - var dt = nowTime - targetTime; - if(dt >= 0){ - if(dt < duration){ - nowTime -= dt; - } - targetTime = nowTime + duration; - callback(); - } - } - }; - that.addTick(tickObj); - return tickObj; - } -}); -window.Hilo.Ticker = Ticker; -})(window); -/** - * Hilo 1.5.0 for standalone - * Copyright 2016 alibaba.com - * Licensed under the MIT License - */ -(function(window){ -if(!window.Hilo) window.Hilo = {}; - - -var arrayProto = Array.prototype, - slice = arrayProto.slice; - -//polyfiil for Array.prototype.indexOf -if (!arrayProto.indexOf) { - arrayProto.indexOf = function(elem, fromIndex){ - fromIndex = fromIndex || 0; - var len = this.length, i; - if(len == 0 || fromIndex >= len) return -1; - if(fromIndex < 0) fromIndex = len + fromIndex; - for(i = fromIndex; i < len; i++){ - if(this[i] === elem) return i; - } - return -1; - }; -} - -var fnProto = Function.prototype; - -//polyfill for Function.prototype.bind -if (!fnProto.bind) { - fnProto.bind = function(thisArg){ - var target = this, - boundArgs = slice.call(arguments, 1), - F = function(){}; - - function bound(){ - var args = boundArgs.concat(slice.call(arguments)); - return target.apply(this instanceof bound ? this : thisArg, args); - } - - F.prototype = target.prototype; - bound.prototype = new F(); - - return bound; - }; -} -window.Hilo.undefined = undefined; -})(window); -/** - * Hilo 1.5.0 for standalone - * Copyright 2016 alibaba.com - * Licensed under the MIT License - */ -(function(window){ -if(!window.Hilo) window.Hilo = {}; -var Hilo = window.Hilo; - -/** - * @language=en - * - *
- * example: - *
- * var bmp = new Bitmap({image:img});
- * Hilo.util.copy(bmp, Hilo.drag);
- * bmp.startDrag([0, 0, 550, 400]);
- * 
- * @class drag A mixin that contains drag method.You can mix drag method to the visual target by use Class.mix(target, drag) or Hilo.util.copy(target, drag). - * @mixin - * @static - * @module hilo/util/drag - * @requires hilo/core/Hilo - */ -var drag = { - _isDragStart:false, - /** - * 是否需要 transform,父元素有 transform 时需要设置为true - * @default false - * @type {Boolean} - */ - dragNeedTransform:false, - /** - * @language=en - * start drag. - * @param {Array} bounds The bounds area that the view can move, relative to the coordinates of the view's parent, [x, y, width, height], default is no limit. - */ - startDrag:function(bounds){ - var that = this; - - if(that._isDragStart){ - that.stopDrag(); - } - that._isDragStart = true; - - var stage; - bounds = bounds||[-Infinity, -Infinity, Infinity, Infinity]; - var mouse = { - x:0, - y:0, - preX:0, - preY:0 - }; - var minX = bounds[0]; - var minY = bounds[1]; - var maxX = bounds[2] == Infinity?Infinity:minX + bounds[2]; - var maxY = bounds[3] == Infinity?Infinity:minY + bounds[3]; - - var worldPoint = { - x:0, - y:0 - }; - - function onStart(e){ - e.stopPropagation(); - updateMouse(e); - that.off(Hilo.event.POINTER_START, onStart); - - worldPoint.x = that.x; - worldPoint.y = that.y; - - if(that.dragNeedTransform && that.parent){ - that.parent.getConcatenatedMatrix().transformPoint(worldPoint); - } - - that.__dragX = worldPoint.x - mouse.x; - that.__dragY = worldPoint.y - mouse.y; - - if(!stage){ - stage = that.getStage(); - } - stage.on(Hilo.event.POINTER_MOVE, onMove); - document.addEventListener(Hilo.event.POINTER_END, onStop); - that.fire("dragStart", mouse); - } - - function onStop(e){ - document.removeEventListener(Hilo.event.POINTER_END, onStop); - stage && stage.off(Hilo.event.POINTER_MOVE, onMove); - - that.on(Hilo.event.POINTER_START, onStart); - that.fire("dragEnd", mouse); - } - - function onMove(e){ - updateMouse(e); - - worldPoint.x = mouse.x + that.__dragX; - worldPoint.y = mouse.y + that.__dragY; - - if(that.dragNeedTransform && that.parent){ - that.parent.getConcatenatedMatrix().invert().transformPoint(worldPoint); - } - - that.x = Math.max(minX, Math.min(maxX, worldPoint.x)); - that.y = Math.max(minY, Math.min(maxY, worldPoint.y)); - that.fire("dragMove", mouse); - } - - function updateMouse(e){ - mouse.preX = mouse.x; - mouse.preY = mouse.y; - mouse.x = e.stageX; - mouse.y = e.stageY; - } - - function stopDrag(){ - that._isDragStart = false; - document.removeEventListener(Hilo.event.POINTER_END, onStop); - stage && stage.off(Hilo.event.POINTER_MOVE, onMove); - that.off(Hilo.event.POINTER_START, onStart); - } - that.on(Hilo.event.POINTER_START, onStart); - - that.stopDrag = stopDrag; - }, - /** - * @language=en - * stop drag. - */ - stopDrag:function(){ - this._isDragStart = false; - } -}; -window.Hilo.drag = drag; -})(window); -/** - * Hilo 1.5.0 for standalone - * Copyright 2016 alibaba.com - * Licensed under the MIT License - */ -(function(window){ -if(!window.Hilo) window.Hilo = {}; -var Class = window.Hilo.Class; - - -/** - * @language=en - * - *
- * Demo: - *
- * ticker.addTick(Hilo.Tween);//Tween works after being added to ticker
- *
- * var view = new View({x:5, y:10});
- * Hilo.Tween.to(view, {
- *     x:100,
- *     y:20,
- *     alpha:0
- * }, {
- *     duration:1000,
- *     delay:500,
- *     ease:Hilo.Ease.Quad.EaseIn,
- *     onComplete:function(){
- *         console.log('complete');
- *     }
- * });
- * 
- * @class Tween class makes tweening (easing, slow motion). - * @param {Object} target Tween target object. - * @param {Object} fromProps Beginning properties of target tweening object. - * @param {Object} toProps Ending properties of target tweening object. - * @param {Object} params Tweening parameters, include all writable Tween class properties. - * @module hilo/tween/Tween - * @requires hilo/core/Class - * @property {Object} target Tween target object, readonly! - * @property {Int} duration Tweening duration, measure in ms. - * @property {Int} delay Tweenning delay time, measure in ms. - * @property {Boolean} paused Is tweening paused, default value is false. - * @property {Boolean} loop Does tweening loop, default value is false. - * @property {Boolean} reverse Does tweening reverse, default value is false. - * @property {Int} repeat Repeat times of tweening, default value is 0. - * @property {Int} repeatDelay Delay time of repeating tweening, measure in ms. - * @property {Function} ease Tweening transform function, default value is null. - * @property {Int} time Time that tweening taken, measure in ms, readonly! - * @property {Function} onStart Function invoked on the beginning of tweening. Require 1 parameter: tween. default value is null. - * @property {Function} onUpdate Function invoked on tweening update. Require 2 parameters: ratio, tween. default value is null. - * @property {Function} onComplete Function invoked on the end of tweening. Require 1 parameter: tween. default value is null. - */ -var Tween = (function(){ - -function now(){ - return +new Date(); -} - -return Class.create(/** @lends Tween.prototype */{ - constructor: function(target, fromProps, toProps, params){ - var me = this; - - me.target = target; - me._startTime = 0; - me._seekTime = 0; - me._pausedTime = 0; - me._pausedStartTime = 0; - me._reverseFlag = 1; - me._repeatCount = 0; - - //no fromProps if pass 3 arguments - if(arguments.length == 3){ - params = toProps; - toProps = fromProps; - fromProps = null; - } - - for(var p in params) me[p] = params[p]; - me._fromProps = fromProps; - me._toProps = toProps; - - //for old version compatiblity - if(!params.duration && params.time){ - me.duration = params.time || 0; - me.time = 0; - } - }, - - target: null, - duration: 1000, - delay: 0, - paused: false, - loop: false, - reverse: false, - repeat: 0, - repeatDelay: 0, - ease: null, - time: 0, //ready only - - isStart:false, - isComplete:false, - onStart: null, - onUpdate: null, - onComplete: null, - - /** - * @language=en - * Set beginning properties and ending properties of tweening object. - * @param {Object} fromProps Beginning properties of target tweening object. - * @param {Object} toProps Ending properties of target tweening object. - * @returns {Tween} Current Tween, for chain calls. - */ - setProps: function(fromProps, toProps){ - var me = this, target = me.target, - propNames = fromProps || toProps, - from = me._fromProps = {}, to = me._toProps = {}; - - fromProps = fromProps || target; - toProps = toProps || target; - - for(var p in propNames){ - to[p] = toProps[p] || 0; - target[p] = from[p] = fromProps[p] || 0; - } - return me; - }, - - /** - * @language=en - * Starting the tweening. - * @returns {Tween} Current Tween, for chain calls. - */ - start: function(){ - var me = this; - me._startTime = now() + me.delay; - me._seekTime = 0; - me._pausedTime = 0; - me._reverseFlag = 1; - me._repeatCount = 0; - me.paused = false; - me.isStart = false; - me.isComplete = false; - Tween.add(me); - return me; - }, - - /** - * @language=en - * Stop the tweening. - * @returns {Tween} Current Tween, for chain calls. - */ - stop: function(){ - Tween.remove(this); - return this; - }, - - /** - * @language=en - * Pause the tweening. - * @returns {Tween} Current Tween, for chain calls. - */ - pause: function(){ - var me = this; - me.paused = true; - me._pausedStartTime = now(); - return me; - }, - - /** - * @language=en - * Continue to play the tweening. - * @returns {Tween} Current Tween, for chain calls. - */ - resume: function(){ - var me = this; - me.paused = false; - if(me._pausedStartTime) me._pausedTime += now() - me._pausedStartTime; - me._pausedStartTime = 0; - return me; - }, - - /** - * @language=en - * Tween jumps to some point. - * @param {Number} time The time to jump to, range from 0 to duration. - * @param {Boolean} pause Is paused. - * @returns {Tween} Current Tween, for chain calls. - */ - seek: function(time, pause){ - var me = this, current = now(); - me._startTime = current; - me._seekTime = time; - me._pausedTime = 0; - if(pause !== undefined) me.paused = pause; - me._update(current, true); - Tween.add(me); - return me; - }, - - /** - * @language=en - * Link next Tween. The beginning time of next Tween depends on the delay value. If delay is a string that begins with '+' or '-', next Tween will begin at (delay) ms after or before the current tween is ended. If delay is out of previous situation, next Tween will begin at (delay) ms after the beginning point of current Tween. - * @param {Tween} tween Tween to link. - * @returns {Tween} next Tween, for chain calls. - */ - link: function(tween){ - var me = this, delay = tween.delay, startTime = me._startTime; - - var plus, minus; - if(typeof delay === 'string'){ - plus = delay.indexOf('+') == 0; - minus = delay.indexOf('-') == 0; - delay = plus || minus ? Number(delay.substr(1)) * (plus ? 1 : -1) : Number(delay); - } - tween.delay = delay; - tween._startTime = plus || minus ? startTime + me.duration + delay : startTime + delay; - - me._next = tween; - Tween.remove(tween); - return tween; - }, - - /** - * @language=en - * Private render method inside Tween class. - * @private - */ - _render: function(ratio){ - var me = this, target = me.target, fromProps = me._fromProps, p; - for(p in fromProps) target[p] = fromProps[p] + (me._toProps[p] - fromProps[p]) * ratio; - }, - - /** - * @language=en - * Private update method inside Tween class. - * @private - */ - _update: function(time, forceUpdate){ - var me = this; - if(me.paused && !forceUpdate) return; - if(me.isComplete) return true; - - //elapsed time - var elapsed = time - me._startTime - me._pausedTime + me._seekTime; - if(elapsed < 0) return; - - //elapsed ratio - var ratio = elapsed / me.duration, complete = false, callback; - ratio = ratio <= 0 ? 0 : ratio >= 1 ? 1 : ratio; - var easeRatio = me.ease ? me.ease(ratio) : ratio; - - if(me.reverse && me.isStart){ - //backward - if(me._reverseFlag < 0) { - ratio = 1 - ratio; - easeRatio = 1 - easeRatio; - } - //forward - if(ratio < 1e-7){ - //repeat complete or not loop - if((me.repeat > 0 && me._repeatCount++ >= me.repeat) || (me.repeat == 0 && !me.loop)){ - complete = true; - }else{ - me._startTime = now(); - me._pausedTime = 0; - me._reverseFlag *= -1; - } - } - } - - //start callback - if(!me.isStart) { - me.setProps(me._fromProps, me._toProps); - me.isStart = true; - if(me.onStart){ - me.onStart.call(me, me); - } - } - me.time = elapsed; - - //render & update callback - me._render(easeRatio); - (callback = me.onUpdate) && callback.call(me, ratio, me); - - //check if complete - if(ratio >= 1){ - if(me.reverse){ - me._startTime = now(); - me._pausedTime = 0; - me._reverseFlag *= -1; - }else if(me.loop || me.repeat > 0 && me._repeatCount++ < me.repeat){ - me._startTime = now() + me.repeatDelay; - me._pausedTime = 0; - }else{ - me.isComplete = true; - } - } - - //next tween - var next = me._next; - if(next && next.time <= 0){ - var nextStartTime = next._startTime; - if(nextStartTime > 0 && nextStartTime <= time){ - //parallel tween - next._render(ratio); - next.time = elapsed; - Tween.add(next); - }else if(me.isComplete && (nextStartTime < 0 || nextStartTime > time)){ - //next tween - next.start(); - } - } - - //complete - if(me.isComplete){ - (callback = me.onComplete) && callback.call(me, me); - return true; - } - }, - - Statics: /** @lends Tween */ { - /** - * @language=en - * @private - */ - _tweens: [], - - /** - * @language=en - * Update all Tween instances. - * @returns {Object} Tween。 - */ - tick: function(){ - var tweens = Tween._tweens, tween, i, len = tweens.length; - - for(i = 0; i < len; i++){ - tween = tweens[i]; - if(tween && tween._update(now())){ - tweens.splice(i, 1); - i--; - } - } - return Tween; - }, - - /** - * @language=en - * Add a Tween instance. - * @param {Tween} tween Tween object to add. - * @returns {Object} Tween。 - */ - add: function(tween){ - var tweens = Tween._tweens; - if(tweens.indexOf(tween) == -1) tweens.push(tween); - return Tween; - }, - - /** - * @language=en - * Remove one Tween target. - * @param {Tween|Object|Array} tweenOrTarget Tween object, target object or an array of object to remove - * @returns {Object} Tween。 - */ - remove: function(tweenOrTarget){ - var i, l; - if(tweenOrTarget instanceof Array){ - for(i = 0, l = tweenOrTarget.length;i < l;i ++){ - Tween.remove(tweenOrTarget[i]); - } - return Tween; - } - - var tweens = Tween._tweens; - if(tweenOrTarget instanceof Tween){ - i = tweens.indexOf(tweenOrTarget); - if(i > -1) tweens.splice(i, 1); - }else{ - for(i = 0; i < tweens.length; i++){ - if(tweens[i].target === tweenOrTarget){ - tweens.splice(i, 1); - i--; - } - } - } - - return Tween; - }, - - /** - * @language=en - * Remove all Tween instances. - * @returns {Object} Tween。 - */ - removeAll: function(){ - Tween._tweens.length = 0; - return Tween; - }, - - /** - * @language=en - * Create a tween, make target object easing from beginning properties to ending properties. - * @param {Object|Array} target Tweening target or tweening target array. - * @param fromProps Beginning properties of target tweening object. - * @param toProps Ending properties of target tweening object. - * @param params Tweening parameters. - * @returns {Tween|Array} An tween instance or an array of tween instance. - */ - fromTo: function(target, fromProps, toProps, params){ - params = params || {}; - var isArray = target instanceof Array; - target = isArray ? target : [target]; - - var tween, i, stagger = params.stagger, tweens = []; - for(i = 0; i < target.length; i++){ - tween = new Tween(target[i], fromProps, toProps, params); - if(stagger) tween.delay = (params.delay || 0) + (i * stagger || 0); - tween.start(); - tweens.push(tween); - } - - return isArray?tweens:tween; - }, - - /** - * @language=en - * Create a tween, make target object easing from current properties to ending properties. - * @param {Object|Array} target Tweening target or tweening target array. - * @param toProps Ending properties of target tweening object. - * @param params Tweening parameters. - * @returns {Tween|Array} An tween instance or an array of tween instance. - */ - to: function(target, toProps, params){ - return Tween.fromTo(target, null, toProps, params); - }, - - /** - * @language=en - * Create a tween, make target object easing from beginning properties to current properties. - * @param {Object|Array} target Tweening target or tweening target array. - * @param fromProps Beginning properties of target tweening object. - * @param params Tweening parameters. - * @returns {Tween|Array} An tween instance or an array of tween instance. - */ - from: function(target, fromProps, params){ - return Tween.fromTo(target, fromProps, null, params); - } - } - -}); - -})(); - -window.Hilo.Tween = Tween; -})(window); -/** - * Hilo 1.5.0 for standalone - * Copyright 2016 alibaba.com - * Licensed under the MIT License - */ -(function(window){ -if(!window.Hilo) window.Hilo = {}; - - -/** - * @language=en - * @class Ease class provides multiple easing functions for Tween. - * @module hilo/tween/Ease - * @static - */ -var Ease = (function(){ - -function createEase(obj, easeInFn, easeOutFn, easeInOutFn, easeNoneFn){ - obj = obj || {}; - easeInFn && (obj.EaseIn = easeInFn); - easeOutFn && (obj.EaseOut = easeOutFn); - easeInOutFn && (obj.EaseInOut = easeInOutFn); - easeNoneFn && (obj.EaseNone = easeNoneFn); - return obj; -} - -/** - * @language=en - * Linear easing function.Include EaseNone. - */ -var Linear = createEase(null, null, null, null, function(k){ - return k; -}); - -/** - * @language=en - * Quad easing function.Include EaseIn, EaseOut, EaseInOut. - */ -var Quad = createEase(null, - function(k){ - return k * k; - }, - - function(k){ - return - k * (k - 2); - }, - - function(k){ - return ((k *= 2) < 1) ? 0.5 * k * k : -0.5 * (--k * (k - 2) - 1); - } -); - -/** - * @language=en - * Cubic easing function.Include EaseIn, EaseOut, EaseInOut. - */ -var Cubic = createEase(null, - function(k){ - return k * k * k; - }, - - function(k){ - return --k * k * k + 1; - }, - - function(k){ - return ((k *= 2) < 1) ? 0.5 * k * k * k : 0.5 * ((k -= 2) * k * k + 2); - } -); - -/** - * @language=en - * Quart easing function.Include EaseIn, EaseOut, EaseInOut. - */ -var Quart = createEase(null, - function(k){ - return k * k * k * k; - }, - - function(k){ - return -(--k * k * k * k - 1); - }, - - function(k){ - return ((k *= 2) < 1) ? 0.5 * k * k * k * k : - 0.5 * ((k -= 2) * k * k * k - 2); - } -); - -/** - * @language=en - * Quint easing function.Include EaseIn, EaseOut, EaseInOut. - */ -var Quint = createEase(null, - function(k){ - return k * k * k * k * k; - }, - - function(k){ - return (k = k - 1) * k * k * k * k + 1; - }, - - function(k){ - return ((k *= 2) < 1) ? 0.5 * k * k * k * k * k : 0.5 * ((k -= 2) * k * k * k * k + 2); - } -); - -var math = Math, - PI = math.PI, HALF_PI = PI * 0.5, - sin = math.sin, cos = math.cos, - pow = math.pow, sqrt = math.sqrt; - -/** - * @language=en - * Sine easing function.Include EaseIn, EaseOut, EaseInOut. - */ -var Sine = createEase(null, - function(k){ - return -cos(k * HALF_PI) + 1; - }, - - function(k){ - return sin(k * HALF_PI); - }, - - function(k){ - return -0.5 * (cos(PI * k) - 1); - } -); - -/** - * @language=en - * Expo easing function.Include EaseIn, EaseOut, EaseInOut. - */ -var Expo = createEase(null, - function(k){ - return k == 0 ? 0 : pow(2, 10 * (k - 1)); - }, - - function(k){ - return k == 1 ? 1 : -pow(2, -10 * k) + 1; - }, - - function(k){ - if(k == 0 || k == 1) return k; - if((k *= 2) < 1) return 0.5 * pow(2, 10 * (k - 1)); - return 0.5 * (-pow(2, - 10 * (k - 1)) + 2); - } -); - -/** - * @language=en - * Circ easing function.Include EaseIn, EaseOut, EaseInOut. - */ -var Circ = createEase(null, - function(k){ - return -(sqrt(1 - k * k) - 1); - }, - - function(k){ - return sqrt(1 - (--k * k)); - }, - - function(k){ - if((k /= 0.5) < 1) return - 0.5 * (sqrt(1 - k * k) - 1); - return 0.5 * (sqrt(1 - (k -= 2) * k) + 1); - } -); - -/** - * @language=en - * Elastic easing function.Include EaseIn, EaseOut, EaseInOut. - */ -var Elastic = createEase( - { - a: 1, - p: 0.4, - s: 0.1, - - config: function(amplitude, period){ - Elastic.a = amplitude; - Elastic.p = period; - Elastic.s = period / (2 * PI) * Math.asin(1 / amplitude) || 0; - } - }, - - function(k){ - return -(Elastic.a * pow(2, 10 * (k -= 1)) * sin((k - Elastic.s) * (2 * PI) / Elastic.p)); - }, - - function(k){ - return (Elastic.a * pow(2, -10 * k) * sin((k - Elastic.s) * (2 * PI) / Elastic.p) + 1); - }, - - function(k){ - return ((k *= 2) < 1) ? -0.5 * (Elastic.a * pow(2, 10 * (k -= 1)) * sin((k - Elastic.s) * (2 * PI) / Elastic.p)) : - Elastic.a * pow(2, -10 * (k -= 1)) * sin((k - Elastic.s) * (2 * PI) / Elastic.p) * 0.5 + 1; - } -); - -/** - * @language=en - * Back easing function.Include EaseIn, EaseOut, EaseInOut. - */ -var Back = createEase( - { - o: 1.70158, - s: 2.59491, - - config: function(overshoot){ - Back.o = overshoot; - Back.s = overshoot * 1.525; - } - }, - - function(k){ - return k * k * ((Back.o + 1) * k - Back.o); - }, - - function(k){ - return (k = k - 1) * k * ((Back.o + 1) * k + Back.o) + 1; - }, - - function(k){ - return ((k *= 2) < 1) ? 0.5 * (k * k * ((Back.s + 1) * k - Back.s)) : 0.5 * ((k -= 2) * k * ((Back.s + 1) * k + Back.s) + 2); - } -); - -/** - * @language=en - * Bounce easing function.Include EaseIn, EaseOut, EaseInOut. - */ -var Bounce = createEase(null, - function(k){ - return 1 - Bounce.EaseOut(1 - k); - }, - - function(k){ - if((k /= 1) < 0.36364){ - return 7.5625 * k * k; - }else if(k < 0.72727){ - return 7.5625 * (k -= 0.54545) * k + 0.75; - }else if(k < 0.90909){ - return 7.5625 * (k -= 0.81818) * k + 0.9375; - }else{ - return 7.5625 * (k -= 0.95455) * k + 0.984375; - } - }, - - function(k){ - return k < 0.5 ? Bounce.EaseIn(k * 2) * 0.5 : Bounce.EaseOut(k * 2 - 1) * 0.5 + 0.5; - } -); - -return { - Linear: Linear, - Quad: Quad, - Cubic: Cubic, - Quart: Quart, - Quint: Quint, - Sine: Sine, - Expo: Expo, - Circ: Circ, - Elastic: Elastic, - Back: Back, - Bounce: Bounce -}; - -})(); -window.Hilo.Ease = Ease; -})(window); -/** - * Hilo 1.5.0 for standalone - * Copyright 2016 alibaba.com - * Licensed under the MIT License - */ -(function(window){ -if(!window.Hilo) window.Hilo = {}; -var Class = window.Hilo.Class; - - -/** - * @language=en - * @private - * @class image resources loader. - * @module hilo/loader/ImageLoader - * @requires hilo/core/Class - */ -var ImageLoader = Class.create({ - load: function(data){ - var me = this; - - var image = new Image(); - if(data.crossOrigin){ - image.crossOrigin = "Anonymous"; - } - - image.onload = function(){ - me.onLoad(image); - }; - image.onerror = image.onabort = me.onError.bind(image); - image.src = data.src + (data.noCache ? (data.src.indexOf('?') == -1 ? '?' : '&') + 't=' + (+new Date()) : ''); - }, - - onLoad: function(image){ - image.onload = image.onerror = image.onabort = null; - return image; - }, - - onError: function(e){ - var image = e.target; - image.onload = image.onerror = image.onabort = null; - return e; - } - -}); -window.Hilo.ImageLoader = ImageLoader; -})(window); -/** - * Hilo 1.5.0 for standalone - * Copyright 2016 alibaba.com - * Licensed under the MIT License - */ -(function(window){ -if(!window.Hilo) window.Hilo = {}; -var Class = window.Hilo.Class; - - -/** - * @language=en - * @private - * @class javascript or JSONP loader - * @module hilo/loader/ScriptLoader - * @requires hilo/core/Class - */ -var ScriptLoader = Class.create({ - load: function(data){ - var me = this, src = data.src, isJSONP = data.type == 'jsonp'; - - if(isJSONP){ - var callbackName = data.callbackName || 'callback'; - var callback = data.callback || 'jsonp' + (++ScriptLoader._count); - var win = window; - - if(!win[callback]){ - win[callback] = function(result){ - delete win[callback]; - }; - } - - src += (src.indexOf('?') == -1 ? '?' : '&') + callbackName + '=' + callback; - } - - if(data.noCache) src += (src.indexOf('?') == -1 ? '?' : '&') + 't=' + (+new Date()); - - var script = document.createElement('script'); - script.type = 'text/javascript'; - script.async = true; - script.onload = me.onLoad.bind(me); - script.onerror = me.onError.bind(me); - script.src = src; - if(data.id) script.id = data.id; - document.getElementsByTagName('head')[0].appendChild(script); - }, - - onLoad: function(e){ - var script = e.target; - script.onload = script.onerror = null; - return script; - }, - - onError: function(e){ - var script = e.target; - script.onload = script.onerror = null; - return e; - }, - - Statics: { - _count: 0 - } - -}); -window.Hilo.ScriptLoader = ScriptLoader; -})(window); -/** - * Hilo 1.5.0 for standalone - * Copyright 2016 alibaba.com - * Licensed under the MIT License - */ -(function(window){ -if(!window.Hilo) window.Hilo = {}; -var Class = window.Hilo.Class; -var EventMixin = window.Hilo.EventMixin; -var ImageLoader = window.Hilo.ImageLoader; -var ScriptLoader = window.Hilo.ScriptLoader; - - -//TODO: 超时timeout,失败重连次数maxTries,更多的下载器Loader,队列暂停恢复等。 - -/** - * @language=en - * @class LoadQueue is a queue-like loader. - * @mixes EventMixin - * @borrows EventMixin#on as #on - * @borrows EventMixin#off as #off - * @borrows EventMixin#fire as #fire - * @param {Object} source resource that need to be loaded,could be a single object or array resource. - * @module hilo/loader/LoadQueue - * @requires hilo/core/Class - * @requires hilo/event/EventMixin - * @requires hilo/loader/ImageLoader - * @requires hilo/loader/ScriptLoader - * @property {Int} maxConnections the limited concurrent connections. default value 2. - */ -var LoadQueue = Class.create(/** @lends LoadQueue.prototype */{ - Mixes: EventMixin, - constructor: function(source){ - this._source = []; - this.add(source); - }, - - maxConnections: 2, //TODO: 应该是每个host的最大连接数。 - - _source: null, - _loaded: 0, - _connections: 0, - _currentIndex: -1, - - /** - * @language=en - * Add desired resource,could be a single object or array resource. - * @param {Object|Array} source ,a single object or array resource. Each resource contains properties like below: - *
    - *
  • id - resource identifier
  • - *
  • src - resource url
  • - *
  • type - resource type. By default, we automatically identify resource by file suffix and choose the relevant loader for you
  • - *
  • loader - specified resource loader. If you specify this,we abandon choosing loader inside
  • - *
  • noCache - a tag that set on or off to prevent cache,implemented by adding timestamp inside
  • - *
  • size - predicted resource size, help calculating loading progress
  • - *
  • crossOrigin - Whether cross-domain is needed, default is false
  • - *
- * @returns {LoadQueue} 下载队列实例本身。 - */ - add: function(source){ - var me = this; - if(source){ - source = source instanceof Array ? source : [source]; - me._source = me._source.concat(source); - } - return me; - }, - - /** - * @language=en - * get resource object by id or src - * @param {String} specified id or src - * @returns {Object} resource object - */ - get: function(id){ - if(id){ - var source = this._source; - for(var i = 0; i < source.length; i++){ - var item = source[i]; - if(item.id === id || item.src === id){ - return item; - } - } - } - return null; - }, - - /** - * @language=en - * get resource object content by id or src - * @param {String} specified id or src - * @returns {Object} resource object content - */ - getContent: function(id){ - var item = this.get(id); - return item && item.content; - }, - - /** - * @language=en - * start loading - * @returns {LoadQueue} the loading instance - */ - start: function(){ - var me = this; - me._loadNext(); - return me; - }, - - /** - * @language=en - * @private - */ - _loadNext: function(){ - var me = this, source = me._source, len = source.length; - - //all items loaded - if(me._loaded >= len){ - me.fire('complete'); - return; - } - - if(me._currentIndex < len - 1 && me._connections < me.maxConnections){ - var index = ++me._currentIndex; - var item = source[index]; - var loader = me._getLoader(item); - - if(loader){ - var onLoad = loader.onLoad, onError = loader.onError; - - loader.onLoad = function(e){ - loader.onLoad = onLoad; - loader.onError = onError; - var content = onLoad && onLoad.call(loader, e) || e.target; - me._onItemLoad(index, content); - }; - loader.onError = function(e){ - loader.onLoad = onLoad; - loader.onError = onError; - onError && onError.call(loader, e); - me._onItemError(index, e); - }; - me._connections++; - } - - me._loadNext(); - loader && loader.load(item); - } - }, - - /** - * @language=en - * @private - */ - _getLoader: function(item){ - var loader = item.loader; - if(loader) return loader; - - var type = item.type || getExtension(item.src); - - switch(type){ - case 'png': - case 'jpg': - case 'jpeg': - case 'gif': - case 'webp': - loader = new ImageLoader(); - break; - case 'js': - case 'jsonp': - loader = new ScriptLoader(); - break; - } - - return loader; - }, - - /** - * @language=en - * @private - */ - _onItemLoad: function(index, content){ - var me = this, item = me._source[index]; - item.loaded = true; - item.content = content; - me._connections--; - me._loaded++; - me.fire('load', item); - me._loadNext(); - }, - - /** - * @language=en - * @private - */ - _onItemError: function(index, e){ - var me = this, item = me._source[index]; - item.error = e; - me._connections--; - me._loaded++; - me.fire('error', item); - me._loadNext(); - }, - - /** - * @language=en - * get resource size, loaded or all. - * @param {Boolean} identify loaded or all resource. default is false, return all resource size. when set true, return loaded resource size. - * @returns {Number} resource size. - */ - getSize: function(loaded){ - var size = 0, source = this._source; - for(var i = 0; i < source.length; i++){ - var item = source[i]; - size += (loaded ? item.loaded && item.size : item.size) || 0; - } - return size; - }, - - /** - * @language=en - * get loaded resource count - * @returns {Uint} loaded resource count - */ - getLoaded: function(){ - return this._loaded; - }, - - /** - * @language=en - * get all resource count - * @returns {Uint} all resource count - */ - getTotal: function(){ - return this._source.length; - } - -}); - -/** - * @language=en - * @private - */ -function getExtension(src){ - var extRegExp = /\/?[^/]+\.(\w+)(\?\S+)?$/i, match, extension; - if(match = src.match(extRegExp)){ - extension = match[1].toLowerCase(); - } - return extension || null; -} -window.Hilo.LoadQueue = LoadQueue; -})(window); -/** - * Hilo 1.5.0 for standalone - * Copyright 2016 alibaba.com - * Licensed under the MIT License - */ -(function(window){ -if(!window.Hilo) window.Hilo = {}; -var Class = window.Hilo.Class; -var util = window.Hilo.util; -var EventMixin = window.Hilo.EventMixin; - - -/** - * @language=en - * @class HTMLAudio is an audio playing module, which uses HTMLAudioElement to play audio. - * Limits: iOS platform requires user action events to start playing, and many Android browser can only play one audio at a time. - * @param {Object} properties create object properties, include all writable properties of this class. - * @module hilo/media/HTMLAudio - * @requires hilo/core/Class - * @requires hilo/util/util - * @requires hilo/event/EventMixin - * @property {String} src The source of the playing audio. - * @property {Boolean} loop Is loop playback, default value is false. - * @property {Boolean} autoPlay Is the audio autoplay, default value is false. - * @property {Boolean} loaded Is the audio resource loaded, readonly! - * @property {Boolean} playing Is the audio playing, readonly! - * @property {Number} duration The duration of the audio, readonly! - * @property {Number} volume The volume of the audio, value between 0 to 1. - * @property {Boolean} muted Is the audio muted, default value is false. - */ -var HTMLAudio = Class.create(/** @lends HTMLAudio.prototype */{ - Mixes: EventMixin, - constructor: function(properties){ - util.copy(this, properties, true); - - this._onAudioEvent = this._onAudioEvent.bind(this); - }, - - src: null, - loop: false, - autoPlay: false, - loaded: false, - playing: false, - duration: 0, - volume: 1, - muted: false, - - _element: null, //HTMLAudioElement对象 - - /** - * @language=en - * Load audio file. - */ - load: function(){ - if(!this._element){ - var elem; - try{ - elem = this._element = new Audio(); - elem.addEventListener('canplaythrough', this._onAudioEvent, false); - elem.addEventListener('ended', this._onAudioEvent, false); - elem.addEventListener('error', this._onAudioEvent, false); - elem.src = this.src; - elem.volume = this.volume; - elem.load(); - } - catch(err){ - //ie9 某些版本有Audio对象,但是执行play,pause会报错! - elem = this._element = {}; - elem.play = elem.pause = function(){ - - }; - } - } - return this; - }, - - /** - * @language=en - * @private - */ - _onAudioEvent: function(e){ - // console.log('onAudioEvent:', e.type); - var type = e.type; - - switch(type){ - case 'canplaythrough': - e.target.removeEventListener(type, this._onAudioEvent); - this.loaded = true; - this.duration = this._element.duration; - this.fire('load'); - if(this.autoPlay) this._doPlay(); - break; - case 'ended': - this.playing = false; - this.fire('end'); - if(this.loop) this._doPlay(); - break; - case 'error': - this.fire('error'); - break; - } - }, - - /** - * @language=en - * @private - */ - _doPlay: function(){ - if(!this.playing){ - this._element.volume = this.muted ? 0 : this.volume; - this._element.play(); - this.playing = true; - } - }, - - /** - * @language=en - * Start playing the audio. And play the audio from the beginning if the audio is already playing. - * Note: To prevent failing to play at the first time, play when the audio is loaded. - */ - play: function(){ - if(this.playing) this.stop(); - - if(!this._element){ - this.autoPlay = true; - this.load(); - }else if(this.loaded){ - this._doPlay(); - } - - return this; - }, - - /** - * @language=en - * Pause (halt) the currently playing audio. - */ - pause: function(){ - if(this.playing){ - this._element.pause(); - this.playing = false; - } - return this; - }, - - /** - * @language=en - * Continue to play the audio. - */ - resume: function(){ - if(!this.playing){ - this._doPlay(); - } - return this; - }, - - /** - * @language=en - * Stop playing the audio. - */ - stop: function(){ - if(this.playing){ - this._element.pause(); - this._element.currentTime = 0; - this.playing = false; - } - return this; - }, - - /** - * @language=en - * Set the volume. Note: iOS devices cannot set volume. - */ - setVolume: function(volume){ - if(this.volume != volume){ - this.volume = volume; - this._element.volume = volume; - } - return this; - }, - - /** - * @language=en - * Set mute mode. Note: iOS devices cannot set mute mode. - */ - setMute: function(muted){ - if(this.muted != muted){ - this.muted = muted; - this._element.volume = muted ? 0 : this.volume; - } - return this; - }, - - Statics: /** @lends HTMLAudio */ { - /** - * @language=en - * Does the browser supports HTMLAudio. - */ - isSupported: window.Audio !== null - } - -}); -window.Hilo.HTMLAudio = HTMLAudio; -})(window); -/** - * Hilo 1.5.0 for standalone - * Copyright 2016 alibaba.com - * Licensed under the MIT License - */ -(function(window){ -if(!window.Hilo) window.Hilo = {}; -var Class = window.Hilo.Class; -var util = window.Hilo.util; -var EventMixin = window.Hilo.EventMixin; - - -/** - * @language=en - * @class WebAudio audio playing module. It provides a better way to play and control audio, use on iOS6+ platform. - * Compatibility:iOS6+、Chrome33+、Firefox28+ supported,but all Android browsers do not support. - * @param {Object} properties create object properties, include all writable properties of this class. - * @module hilo/media/WebAudio - * @requires hilo/core/Class - * @requires hilo/util/util - * @requires hilo/event/EventMixin - * @property {String} src The source of the playing audio. - * @property {Boolean} loop Is loop playback, default value is false. - * @property {Boolean} autoPlay Is the audio autoplay, default value is false. - * @property {Boolean} loaded Is the audio resource loaded, readonly! - * @property {Boolean} playing Is the audio playing, readonly! - * @property {Number} duration The duration of the audio, readonly! - * @property {Number} volume The volume of the audio, value between 0 to 1. - * @property {Boolean} muted Is the audio muted, default value is false. - */ -var WebAudio = (function(){ - -var context = null; -try { - var AudioContext = window.AudioContext || window.webkitAudioContext; - if (AudioContext) { - context = new AudioContext(); - } -} catch(e) { - context = null; -} - -return Class.create(/** @lends WebAudio.prototype */{ - Mixes: EventMixin, - constructor: function(properties){ - util.copy(this, properties, true); - - this._init(); - }, - - src: null, - loop: false, - autoPlay: false, - loaded: false, - playing: false, - duration: 0, - volume: 1, - muted: false, - - _context: null, //WebAudio上下文 the WebAudio Context - _gainNode: null, //音量控制器 the volume controller - _buffer: null, //音频缓冲文件 the audio file buffer - _audioNode: null, //音频播放器 the audio playing node - _startTime: 0, //开始播放时间戳 the start time to play the audio - _offset: 0, //播放偏移量 the offset of current playing audio - - /** - * @language=en - * @private Initialize. - */ - _init:function(){ - this._context = context; - this._gainNode = context.createGain ? context.createGain() : context.createGainNode(); - this._gainNode.connect(context.destination); - - this._onAudioEvent = this._onAudioEvent.bind(this); - this._onDecodeComplete = this._onDecodeComplete.bind(this); - this._onDecodeError = this._onDecodeError.bind(this); - }, - /** - * @language=en - * Load audio file. Note: use XMLHttpRequest to load the audio, should pay attention to cross-origin problem. - */ - load: function(){ - if(!this._buffer){ - var buffer = WebAudio._bufferCache[this.src]; - if(buffer){ - this._onDecodeComplete(buffer); - } - else{ - var request = new XMLHttpRequest(); - request.src = this.src; - request.open('GET', this.src, true); - request.responseType = 'arraybuffer'; - request.onload = this._onAudioEvent; - request.onprogress = this._onAudioEvent; - request.onerror = this._onAudioEvent; - request.send(); - } - this._buffer = true; - } - return this; - }, - - /** - * @private - */ - _onAudioEvent: function(e){ - // console.log('onAudioEvent:', e.type); - var type = e.type; - - switch(type){ - case 'load': - var request = e.target; - request.onload = request.onprogress = request.onerror = null; - this._context.decodeAudioData(request.response, this._onDecodeComplete, this._onDecodeError); - request = null; - break; - case 'ended': - this.playing = false; - this.fire('end'); - if(this.loop) this._doPlay(); - break; - case 'progress': - this.fire(e); - break; - case 'error': - this.fire(e); - break; - } - }, - - /** - * @private - */ - _onDecodeComplete: function(audioBuffer){ - if(!WebAudio._bufferCache[this.src]){ - WebAudio._bufferCache[this.src] = audioBuffer; - } - - this._buffer = audioBuffer; - this.loaded = true; - this.duration = audioBuffer.duration; - - this.fire('load'); - if(this.autoPlay) this._doPlay(); - }, - - /** - * @private - */ - _onDecodeError: function(){ - this.fire('error'); - }, - - /** - * @private - */ - _doPlay: function(){ - this._clearAudioNode(); - - var audioNode = this._context.createBufferSource(); - - //some old browser are noteOn/noteOff -> start/stop - if(!audioNode.start){ - audioNode.start = audioNode.noteOn; - audioNode.stop = audioNode.noteOff; - } - - audioNode.buffer = this._buffer; - audioNode.onended = this._onAudioEvent; - this._gainNode.gain.value = this.muted ? 0 : this.volume; - audioNode.connect(this._gainNode); - audioNode.start(0, this._offset); - - this._audioNode = audioNode; - this._startTime = this._context.currentTime; - this.playing = true; - }, - - /** - * @private - */ - _clearAudioNode: function(){ - var audioNode = this._audioNode; - if(audioNode){ - audioNode.onended = null; - // audioNode.disconnect(this._gainNode); - audioNode.disconnect(0); - this._audioNode = null; - } - }, - - /** - * @language=en - * Play the audio. Restart playing the audio from the beginning if already playing. - */ - play: function(){ - if(this.playing) this.stop(); - - if(this.loaded){ - this._doPlay(); - }else if(!this._buffer){ - this.autoPlay = true; - this.load(); - } - - return this; - }, - - /** - * @language=en - * Pause (halt) playing the audio. - */ - pause: function(){ - if(this.playing){ - this._audioNode.stop(0); - this._offset += this._context.currentTime - this._startTime; - this.playing = false; - } - return this; - }, - - /** - * @language=en - * Continue to play the audio. - */ - resume: function(){ - if(!this.playing){ - this._doPlay(); - } - return this; - }, - - /** - * @language=en - * Stop playing the audio. - */ - stop: function(){ - if(this.playing){ - this._audioNode.stop(0); - this._audioNode.disconnect(); - this._offset = 0; - this.playing = false; - } - return this; - }, - - /** - * @language=en - * Set the volume. - */ - setVolume: function(volume){ - if(this.volume != volume){ - this.volume = volume; - this._gainNode.gain.value = volume; - } - return this; - }, - - /** - * @language=en - * Set mute mode. - */ - setMute: function(muted){ - if(this.muted != muted){ - this.muted = muted; - this._gainNode.gain.value = muted ? 0 : this.volume; - } - return this; - }, - - Statics: /** @lends WebAudio */ { - /** - * @language=en - * Does the browser support WebAudio. - */ - isSupported: context !== null, - - /** - * @language=en - * Does browser activate WebAudio already. - */ - enabled: false, - - /** - * @language=en - * Activate WebAudio. Note: Require user action events to activate. Once activated, can play audio without user action events. - */ - enable: function(){ - if(!this.enabled && context){ - var source = context.createBufferSource(); - source.buffer = context.createBuffer(1, 1, 22050); - source.connect(context.destination); - source.start ? source.start(0, 0, 0) : source.noteOn(0, 0, 0); - this.enabled = true; - return true; - } - return this.enabled; - }, - /** - * The audio buffer caches. - * @private - * @type {Object} - */ - _bufferCache:{}, - /** - * @language=en - * Clear the audio buffer cache. - * @param {String} url audio's url. if url is none, it will clear all buffer. - */ - clearBufferCache:function(url){ - if(url){ - this._bufferCache[url] = null; - } - else{ - this._bufferCache = {}; - } - } - } -}); - -})(); -window.Hilo.WebAudio = WebAudio; -})(window); -/** - * Hilo 1.5.0 for standalone - * Copyright 2016 alibaba.com - * Licensed under the MIT License - */ -(function(window){ -if(!window.Hilo) window.Hilo = {}; -var HTMLAudio = window.Hilo.HTMLAudio; -var WebAudio = window.Hilo.WebAudio; -var util = window.Hilo.util; - - -/** - * @language=en - * - *
- * demo: - *
- * var audio = WebSound.getAudio({
- *     src: 'test.mp3',
- *     loop: false,
- *     volume: 1
- * }).on('load', function(e){
- *     console.log('load');
- * }).on('end', function(e){
- *     console.log('end');
- * }).play();
- * 
- * @class Audio playing manager. - * @static - * @module hilo/media/WebSound - * @requires hilo/media/HTMLAudio - * @requires hilo/media/WebAudio - * @requires hilo/util/util - */ -var WebSound = { - _audios: {}, - - /** - * @language=en - * Activate audio function. Note: Require user action events to activate. Currently support WebAudio. - */ - enableAudio: function(){ - if(WebAudio.isSupported){ - WebAudio.enable(); - } - }, - - /** - * @language=en - * Get audio element. Default use WebAudio if supported. - * @param {String|Object} source If String, it's the source of the audio; If Object, it should contains a src property. - * @param {Boolean} [preferWebAudio=true] Whether or not to use WebAudio first, default is true. - * @returns {WebAudio|HTMLAudio} Audio playing instance. - */ - getAudio: function(source, preferWebAudio){ - if(preferWebAudio === undefined){ - preferWebAudio = true; - } - - source = this._normalizeSource(source); - var audio = this._audios[source.src]; - if(!audio){ - if(preferWebAudio && WebAudio.isSupported){ - audio = new WebAudio(source); - }else if(HTMLAudio.isSupported){ - audio = new HTMLAudio(source); - } - this._audios[source.src] = audio; - } - - return audio; - }, - - /** - * @language=en - * Remove audio element. - * @param {String|Object} source If String, it's the source of the audio; If Object, it should contains a src property. - */ - removeAudio: function(source){ - var src = typeof source === 'string' ? source : source.src; - var audio = this._audios[src]; - if(audio){ - audio.stop(); - audio.off(); - this._audios[src] = null; - delete this._audios[src]; - } - }, - - /** - * @language=en - * @private - */ - _normalizeSource: function(source){ - var result = {}; - if(typeof source === 'string') result = {src:source}; - else util.copy(result, source); - return result; - } - -}; -window.Hilo.WebSound = WebSound; -})(window); -/** - * Hilo 1.5.0 for standalone - * Copyright 2016 alibaba.com - * Licensed under the MIT License - */ -(function(window){ -if(!window.Hilo) window.Hilo = {}; -var Class = window.Hilo.Class; -var util = window.Hilo.util; - - -/** - * @language=en - * @class Camera. - * @param {Object} properties The properties to create a view object, contains all writeable props of this class - * @module hilo/game/Camera - * @requires hilo/core/Class - * @requires hilo/util/util - * @property {Number} width The width of the camera. - * @property {Number} height The height of the camera. - * @property {Object} scroll The scrolling value of the camera {x:0, y:0}. - * @property {View} target The target that the camera follow. - * @property {Array} bounds The rect area where camera is allowed to move [x, y, width, height]. - * @property {Array} deadzone The rect area where camera isn't allowed to move[ x, y, width, height]. - */ -var Camera = Class.create(/** @lends Camera.prototype */{ - constructor:function(properties){ - this.width = 0; - this.height = 0; - - this.target = null; - this.deadzone = null; - this.bounds = null; - - this.scroll = { - x:0, - y:0 - }; - - util.copy(this, properties); - }, - /** - * @language=en - * update. - * @param {Number} deltaTime - */ - tick:function(deltaTime){ - var target = this.target; - var scroll = this.scroll; - var bounds = this.bounds; - var deadzone = this.deadzone; - - if(target){ - var viewX, viewY; - if(deadzone){ - viewX = Math.min(Math.max(target.x - scroll.x, deadzone[0]), deadzone[0] + deadzone[2]); - viewY = Math.min(Math.max(target.y - scroll.y, deadzone[1]), deadzone[1] + deadzone[3]); - } - else{ - viewX = this.width * .5; - viewY = this.height * .5; - } - - scroll.x = target.x - viewX; - scroll.y = target.y - viewY; - - if(bounds){ - scroll.x = Math.min(Math.max(scroll.x, bounds[0]), bounds[0] + bounds[2]); - scroll.y = Math.min(Math.max(scroll.y, bounds[1]), bounds[1] + bounds[3]); - } - } - else{ - scroll.x = 0; - scroll.y = 0; - } - }, - /** - * @language=en - * Follow the target. - * @param {Object} target The target that the camera follow. It must has x and y properties. - * @param {Array} deadzone The rect area where camera isn't allowed to move[ x, y, width, height]. - */ - follow:function(target, deadzone){ - this.target = target; - if(deadzone !== undefined){ - this.deadzone = deadzone; - } - this.tick(); - } -}); - -window.Hilo.Camera = Camera; -})(window); -/** - * Hilo 1.5.0 for standalone - * Copyright 2016 alibaba.com - * Licensed under the MIT License - */ -(function(window){ -if(!window.Hilo) window.Hilo = {}; -var Class = window.Hilo.Class; -var util = window.Hilo.util; - - -/** - * @language=en - * @class Camera3d is a pseudo-3d camera. - * @module hilo/game/Camera3d - * @requires hilo/core/Class - * @requires hilo/util/util - * @property {Number} fv The distance of the fov(The distance between eyes and the Z plane,it determines the scale ratio of the 3d object). - * @property {Number} fx The x position of the screen viewpoint(The distance between the screen viewpoint and the screen left top corner on the x axis). - * @property {Number} fy The y position of the screen viewpoint(The distance between the screen viewpoint and the screen left top corner on the y axis). - * @property {Object} stage The 3d object's container, it can be stage or container.It is required if you need to sort the 3d object by z axis. - * @property {Number} x The x position. - * @property {Number} y The y position. - * @property {Number} z The z position. - * @property {Number} rotationX The x rotation. - * @property {Number} rotationY The y rotation. - * @property {Number} rotationZ The z rotation. - */ -var Camera3d = (function(){ - - var degtorad = Math.PI / 180; - - //Rotate the axis. - function rotateX(x, y, z, ca, sa) {//rotate x - return { - x: x, - y: y * ca - z * sa, - z: y * sa + z * ca - }; - } - function rotateY(x, y, z, ca, sa) {//rotate y - return { - x: x * ca - z * sa, - y: y, - z: x * sa + z * ca - }; - } - function rotateZ(x, y, z, ca, sa) {//rotate z - return { - x: x * ca - y * sa, - y: x * sa + y * ca, - z: z - }; - } - - var Camera3d = Class.create(/** @lends Camera3d.prototype */{ - - constructor: function(properties){ - properties.x = properties.x || 0; - properties.y = properties.y || 0; - properties.z = properties.z || 0; - properties.rotationX = properties.rotationX || 0; - properties.rotationY = properties.rotationY || 0; - properties.rotationZ = properties.rotationZ || 0; - - util.copy(this, properties); - }, - - /** - * @language=en - * Translate the camera,used for Zoomin/out feature. - * @param {Number} x The x position. - * @param {Number} y The y position. - * @param {Number} z The z position. - */ - translate : function(x,y,z){ - this.tx = x; - this.ty = y; - this.tz = z; - }, - - /** - * @language=en - * Rotate by the x axis. - * @param {Number} angle The rotate degree. - */ - rotateX : function(angle){ - this.rotationX = angle; - }, - - /** - * @language=en - * Rotate by the y axis. - * @param {Number} angle The rotate degree. - */ - rotateY : function(angle){ - this.rotationY = angle; - }, - - /** - * @language=en - * Rotate by the z axis. - * @param {Number} angle The rotate degree. - */ - rotateZ : function(angle){ - this.rotationZ = angle; - }, - - /** - * @language=en - * Project the 3d point to 2d point. - * @param {object} vector3D The 3d position, it must have x, y and z properties. - * @param {View} view The view related to the 3d position.It'll be auto translated by the 3d position. - * @returns {Object} The 2d object include z and scale properties, e.g.:{x:x, y:y, z:z, scale} - */ - project : function(vector3D, view){ - - var rx = this.rotationX * degtorad, - ry = this.rotationY * degtorad, - rz = this.rotationZ * degtorad, - - cosX = Math.cos(rx), sinX = Math.sin(rx), - cosY = Math.cos(ry), sinY = Math.sin(ry), - cosZ = Math.cos(rz), sinZ = Math.sin(rz), - - // 旋转变换前的 仿射矩阵位移, - dx = vector3D.x - this.x, - dy = vector3D.y - this.y, - dz = vector3D.z - this.z; - - // 旋转矩阵变换 - var vector = rotateZ(dx, dy, dz, cosZ, sinZ); - vector = rotateY(vector.x, vector.y, vector.z, cosY, sinY); - vector = rotateX(vector.x, vector.y, vector.z, cosX, sinX); - - // 最后的仿射矩阵变换 - if(this.tx) vector.x -= this.tx; - if(this.ty) vector.y -= this.ty; - if(this.tz) vector.z -= this.tz; - - var perspective = this.fv / (this.fv + vector.z), - _x = vector.x * perspective, - _y = -vector.y * perspective; - - var result = { - x : _x + this.fx, - y : _y + this.fy, - z : -vector.z, - scale : perspective - }; - - if(view){ - view.x = result.x; - view.y = result.y; - view.z = result.z; - view.scaleX = result.scale; - view.scaleY = result.scale; - } - - return result; - }, - - /** - * @language=en - * Sort by z axis. - */ - sortZ : function(){ - this.stage.children.sort(function(view_a, view_b){ - return view_a.z > view_b.z; - }); - }, - - /** - * @language=en - * Used for the ticker. - */ - tick : function(){ - this.sortZ(); - } - - }); - - return Camera3d; - -})(); -window.Hilo.Camera3d = Camera3d; -})(window); -/** - * Hilo 1.5.0 for standalone - * Copyright 2016 alibaba.com - * Licensed under the MIT License - */ -(function(window){ -if(!window.Hilo) window.Hilo = {}; -var Hilo = window.Hilo;var Class = window.Hilo.Class; -var View = window.Hilo.View; -var Container = window.Hilo.Container; -var Drawable = window.Hilo.Drawable; -var util = window.Hilo.util; - - -/** - * @language=en - * - *
- * @class ParticleSystem A particle system. - * @augments Container - * @module hilo/game/ParticleSystem - * @requires hilo/core/Hilo - * @requires hilo/core/Class - * @requires hilo/view/View - * @requires hilo/view/Container - * @requires hilo/view/Drawable - * @requires hilo/util/util - * @property {Number} [emitTime=0.2] Emit time interval(in second). - * @property {Number} [emitTimeVar=0] Emit time interval variances. - * @property {Number} [emitNum=10] Emit number. - * @property {Number} [emitNumVar=0] Emit number variances. - * @property {Number} [emitterX=0] The emitter x position. - * @property {Number} [emitterY=0] The emitter y position. - * @property {Number} [totalTime=Infinity] Total time. - * @property {Number} [gx=0] The gravity x value. - * @property {Number} [gy=0] The gravity y value. - * @param {Object} properties properties The properties to create a view object, contains all writeable props of this class - * @param {Object} properties.particle The config of particle. - * @param {Number} [properties.particle.x=0] The x position. - * @param {Number} [properties.particle.y=0] The y position - * @param {Number} [properties.particle.vx=0] The x velocity. - * @param {Number} [properties.particle.vy=0] The y velocity. - * @param {Number} [properties.particle.ax=0] The x acceleration. - * @param {Number} [properties.particle.ay=0] The y acceleration. - * @param {Number} [properties.particle.life=1] The time particle lives(in second). - * @param {Number} [properties.particle.alpha=1] The alpha. - * @param {Number} [properties.particle.alphaV=0] The alpha decline rate. - * @param {Number} [properties.particle.scale=1] The scale. - * @param {Number} [properties.particle.scaleV=0] The scale decline rate. -*/ -var ParticleSystem = (function(){ - //粒子属性 - var props = ['x', 'y', 'vx', 'vy', 'ax', 'ay', 'rotation', 'rotationV', 'scale', 'scaleV', 'alpha', 'alphaV', 'life']; - var PROPS = []; - for(var i = 0, l = props.length;i < l;i ++){ - var p = props[i]; - PROPS.push(p); - PROPS.push(p + "Var"); - } - - //粒子默认值 - var PROPS_DEFAULT = { - x: 0, - y: 0, - vx: 0, - vy: 0, - ax: 0, - ay: 0, - scale:1, - scaleV:0, - alpha:1, - alphaV:0, - rotation: 0, - rotationV: 0, - life: 1 - }; - - var diedParticles = []; - - var ParticleSystem = Class.create(/** @lends ParticleSystem.prototype */{ - Extends:Container, - constructor:function(properties){ - this.id = this.id || properties.id || Hilo.getUid("ParticleSystem"); - - this.emitterX = 0; - this.emitterY = 0; - - this.gx = 0; - this.gy = 0; - this.totalTime = Infinity; - - this.emitNum = 10; - this.emitNumVar = 0; - - this.emitTime = .2; - this.emitTimeVar = 0; - - this.particle = {}; - - ParticleSystem.superclass.constructor.call(this, properties); - - this.reset(properties); - }, - Statics:{ - PROPS:PROPS, - PROPS_DEFAULT:PROPS_DEFAULT, - diedParticles:diedParticles - }, - /** - * @language=en - * Reset the properties. - * @param {Object} cfg - */ - reset: function(cfg) { - util.copy(this, cfg); - this.particle.system = this; - if(this.totalTime <= 0){ - this.totalTime = Infinity; - } - }, - /** - * @language=en - * 更新 - * @param {Number} dt delta time(in milliseconds) - */ - onUpdate: function(dt) { - dt *= .001; - if (this._isRun) { - this._totalRunTime += dt; - this._currentRunTime += dt; - if (this._currentRunTime >= this._emitTime) { - this._currentRunTime = 0; - this._emitTime = getRandomValue(this.emitTime, this.emitTimeVar); - this._emit(); - } - - if (this._totalRunTime >= this.totalTime) { - this.stop(); - } - } - }, - /** - * @language=en - * Emit particles. - */ - _emit: function() { - var num = getRandomValue(this.emitNum, this.emitNumVar)>>0; - for (var i = 0; i < num; i++) { - this.addChild(Particle.create(this.particle)); - } - }, - /** - * @language=en - * Start emit particles. - */ - start: function() { - this.stop(true); - this._currentRunTime = 0; - this._totalRunTime = 0; - this._isRun = true; - this._emitTime = getRandomValue(this.emitTime, this.emitTimeVar); - }, - /** - * @language=en - * Stop emit particles. - * @param {Boolean} clear Whether or not clear all the particles. - */ - stop: function(clear) { - this._isRun = false; - if (clear) { - for (var i = this.children.length - 1; i >= 0; i--) { - this.children[i].destroy(); - } - } - } - }); - - /** - * @language=en - * @class 粒子 - * @inner - * @param {Number} vx The x velocity. - * @param {Number} vy The y velocity. - * @param {Number} ax The x acceleration. - * @param {Number} ay The y acceleration. - * @param {Number} scaleV The scale decline rate. - * @param {Number} alphaV The alpha decline rate. - * @param {Number} rotationV The rotate speed. - * @param {Number} life The time particle lives(in seconds) - */ - var Particle = Class.create({ - Extends:View, - constructor:function(properties){ - this.id = this.id || properties.id || Hilo.getUid("Particle"); - Particle.superclass.constructor.call(this, properties); - this.init(properties); - }, - /** - * @language=en - * Update the particle. - */ - onUpdate: function(dt) { - dt *= .001; - if(this._died){ - return false; - } - var ax = this.ax + this.system.gx; - var ay = this.ay + this.system.gy; - - this.vx += ax * dt; - this.vy += ay * dt; - this.x += this.vx * dt; - this.y += this.vy * dt; - - this.rotation += this.rotationV; - - if (this._time > .1) { - this.alpha += this.alphaV; - } - - this.scale += this.scaleV; - this.scaleX = this.scaleY = this.scale; - - this._time += dt; - if (this._time >= this.life || this.alpha <= 0) { - this.destroy(); - return false; - } - }, - /** - * @language=en - * Set the image of particle. - */ - setImage: function(img, frame) { - this.drawable = this.drawable||new Drawable(); - frame = frame || [0, 0, img.width, img.height]; - - this.width = frame[2]; - this.height = frame[3]; - this.drawable.rect = frame; - this.drawable.image = img; - }, - /** - * @language=en - * Destroy the particle. - */ - destroy: function() { - this._died = true; - this.alpha = 0; - this.removeFromParent(); - diedParticles.push(this); - }, - /** - * @language=en - * Init the particle. - */ - init: function(cfg) { - this.system = cfg.system; - this._died = false; - this._time = 0; - this.alpha = 1; - for (var i = 0, l = PROPS.length; i < l; i++) { - var p = PROPS[i]; - var v = cfg[p] === undefined ? PROPS_DEFAULT[p] : cfg[p]; - this[p] = getRandomValue(v, cfg[p + 'Var']); - } - - this.x += this.system.emitterX; - this.y += this.system.emitterY; - - if (cfg.image) { - var frame = cfg.frame; - if(frame && frame[0].length){ - frame = frame[(Math.random() * frame.length) >> 0]; - } - this.setImage(cfg.image, frame); - if(cfg.pivotX !== undefined){ - this.pivotX = cfg.pivotX * frame[2]; - } - if(cfg.pivotY !== undefined){ - this.pivotY = cfg.pivotY * frame[3]; - } - } - }, - Statics:{ - /** - * @language=en - * Create the particle. - * @param {Object} cfg The config of particle. - */ - create:function(cfg) { - if (diedParticles.length > 0) { - var particle = diedParticles.pop(); - particle.init(cfg); - return particle; - } else { - return new Particle(cfg); - } - } - } - - }); - - /** - * Get the random value. - * @private - * @param {Number} value The value. - * @param {Number} variances The variances. - * @return {Number} - */ - function getRandomValue(value, variances){ - return variances ? value + (Math.random() - .5) * 2 * variances : value; - } - - return ParticleSystem; -})(); -window.Hilo.ParticleSystem = ParticleSystem; -})(window); \ No newline at end of file +!function(t){t.Hilo||(t.Hilo={});var e=function(){var e=navigator.userAgent,i=document,n=t,r=i.documentElement,a={iphone:/iphone/i.test(e),ipad:/ipad/i.test(e),ipod:/ipod/i.test(e),ios:/iphone|ipad|ipod/i.test(e),android:/android/i.test(e),webkit:/webkit/i.test(e),chrome:/chrome/i.test(e),safari:/safari/i.test(e),firefox:/firefox/i.test(e),ie:/msie/i.test(e),opera:/opera/i.test(e),supportTouch:"ontouchstart"in n,supportCanvas:null!=i.createElement("canvas").getContext,supportStorage:!1,supportOrientation:"orientation"in n||"orientation"in n.screen,supportDeviceMotion:"ondevicemotion"in n};try{var o="hilo";localStorage.setItem(o,o),localStorage.removeItem(o),a.supportStorage=!0}catch(s){}var l=a.jsVendor=a.webkit?"webkit":a.firefox?"webkit":a.opera?"o":a.ie?"ms":"",h=a.cssVendor="-"+l+"-",c=i.createElement("div"),u=c.style,d=void 0!=u[l+"Transform"],f=void 0!=u[l+"Perspective"];f&&(c.id="test3d",u=i.createElement("style"),u.textContent="@media ("+h+"transform-3d){#test3d{height:3px}}",i.head.appendChild(u),r.appendChild(c),f=3==c.offsetHeight,i.head.removeChild(u),r.removeChild(c)),a.supportTransform=d,a.supportTransform3D=f;var p=a.supportTouch,v=p?"touchstart":"mousedown",m=p?"touchmove":"mousemove",_=p?"touchend":"mouseup";return a.POINTER_START=v,a.POINTER_MOVE=m,a.POINTER_END=_,a}();t.Hilo.browser=e}(window),function(t){t.Hilo||(t.Hilo={});var e={copy:function(t,e,i){for(var n in e)i&&!t.hasOwnProperty(n)&&void 0===t[n]||(t[n]=e[n]);return t}};t.Hilo.util=e}(window),function(t){t.Hilo||(t.Hilo={});var e=t.Hilo.browser,i=t.Hilo.util,n=t,r=document,a=r.documentElement,o=0,s={},l={version:"1.6.0",getUid:function(t){var e=++o;if(t){var i=t.charCodeAt(t.length-1);return i>=48&&i<=57&&(t+="_"),t+e}return e},viewToString:function(t){for(var e,i=t;i;)e=e?i.id+"."+e:i.id,i=i.parent;return e},copy:function(t,e,n){return i.copy(t,e,n),s.copy||(s.copy=!0,console.warn("Hilo.copy has been Deprecated! Use Hilo.util.copy instead.")),t},browser:e,event:{POINTER_START:e.POINTER_START,POINTER_MOVE:e.POINTER_MOVE,POINTER_END:e.POINTER_END},align:{TOP_LEFT:"TL",TOP:"T",TOP_RIGHT:"TR",LEFT:"L",CENTER:"C",RIGHT:"R",BOTTOM_LEFT:"BL",BOTTOM:"B",BOTTOM_RIGHT:"BR"},getElementRect:function(t){var e;try{e=t.getBoundingClientRect()}catch(i){e={top:t.offsetTop,left:t.offsetLeft,right:t.offsetLeft+t.offsetWidth,bottom:t.offsetTop+t.offsetHeight}}var r=(n.pageXOffset||a.scrollLeft)-(a.clientLeft||0)||0,o=(n.pageYOffset||a.scrollTop)-(a.clientTop||0)||0,s=n.getComputedStyle?getComputedStyle(t):t.currentStyle,l=parseInt,h=l(s.paddingLeft)+l(s.borderLeftWidth)||0,c=l(s.paddingTop)+l(s.borderTopWidth)||0,u=l(s.paddingRight)+l(s.borderRightWidth)||0,d=l(s.paddingBottom)+l(s.borderBottomWidth)||0,f=e.top||0,p=e.left||0,v=e.right||0,m=e.bottom||0;return{left:p+r+h,top:f+o+c,width:v-u-p-h,height:m-d-f-c}},createElement:function(t,e){var i,n,a,o=r.createElement(t);for(i in e)if(n=e[i],"style"===i)for(a in n)o.style[a]=n[a];else o[i]=n;return o},getElement:function(t){return r.getElementById(t)},setElementStyleByView:function(t){var e=t.drawable,i=e.domElement.style,n=t._stateCache||(t._stateCache={}),r=l.browser.jsVendor,a="px",o=!1;if(this.cacheStateIfChanged(t,["visible"],n)&&(i.display=t.visible?"":"none"),this.cacheStateIfChanged(t,["alpha"],n)&&(i.opacity=t.alpha),t.visible&&!(t.alpha<=0)){if(this.cacheStateIfChanged(t,["width"],n)&&(i.width=t.width+a),this.cacheStateIfChanged(t,["height"],n)&&(i.height=t.height+a),this.cacheStateIfChanged(t,["depth"],n)&&(i.zIndex=t.depth+1),t.transform){var s=t.transform;(o=this.cacheStateIfChanged(t,["pivotX","pivotY"],n))&&(i[r+"TransformOrigin"]="0 0"),i[r+"Transform"]="matrix3d("+s.a+", "+s.b+", 0, 0, "+s.c+", "+s.d+", 0, 0, 0, 0, 1, 0, "+s.tx+", "+s.ty+", 0, 1)"}else(o=this.cacheStateIfChanged(t,["pivotX","pivotY"],n))&&(i[r+"TransformOrigin"]=t.pivotX+a+" "+t.pivotY+a),(this.cacheStateIfChanged(t,["x","y","rotation","scaleX","scaleY"],n)||o)&&(i[r+"Transform"]=this.getTransformCSS(t));this.cacheStateIfChanged(t,["background"],n)&&(i.backgroundColor=t.background),i.pointerEvents||(i.pointerEvents="none");var h=e.image;if(h){var c=h.src;c!==n.image&&(n.image=c,i.backgroundImage="url("+c+")");var u=e.rect;if(u){var d=u[0],f=u[1];d!==n.sx&&(n.sx=d,i.backgroundPositionX=-d+a),f!==n.sy&&(n.sy=f,i.backgroundPositionY=-f+a)}}var p=t.mask;if(p){var v=p.drawable.domElement.style.backgroundImage;v!==n.maskImage&&(n.maskImage=v,i[r+"MaskImage"]=v,i[r+"MaskRepeat"]="no-repeat");var m=p.x,_=p.y;m===n.maskX&&_===n.maskY||(n.maskX=m,n.maskY=_,i[r+"MaskPosition"]=m+a+" "+_+a)}}},cacheStateIfChanged:function(t,e,i){var n,r,a,o,s=!1;for(n=0,r=e.length;n=6?(e=s[0],i=s[1],n=s[2],r=s[3],a=s[4],o=s[5]):(e=t.a,i=t.b,n=t.c,r=t.d,a=t.tx,o=t.ty),this.a=l*e+h*n,this.b=l*i+h*r,this.c=c*e+u*n,this.d=c*i+u*r,this.tx=d*e+f*n+a,this.ty=d*i+f*r+o,this},rotate:function(t){var e=Math.sin(t),i=Math.cos(t),n=this.a,r=this.b,a=this.c,o=this.d,s=this.tx,l=this.ty;return this.a=n*i-r*e,this.b=n*e+r*i,this.c=a*i-o*e,this.d=a*e+o*i,this.tx=s*i-l*e,this.ty=s*e+l*i,this},scale:function(t,e){return this.a*=t,this.d*=e,this.c*=t,this.b*=e,this.tx*=t,this.ty*=e,this},translate:function(t,e){return this.tx+=t,this.ty+=e,this},identity:function(){return this.a=this.d=1,this.b=this.c=this.tx=this.ty=0,this},invert:function(){var t=this.a,e=this.b,i=this.c,n=this.d,r=this.tx,a=t*n-e*i;return this.a=n/a,this.b=-e/a,this.c=-i/a,this.d=t/a,this.tx=(i*this.ty-n*r)/a,this.ty=-(t*this.ty-e*r)/a,this},transformPoint:function(t,e,i){var n=t.x*this.a+t.y*this.c+this.tx,r=t.x*this.b+t.y*this.d+this.ty;return e&&(n=n+.5>>0,r=r+.5>>0),i?{x:n,y:r}:(t.x=n,t.y=r,t)}});t.Hilo.Matrix=i}(window),function(t){t.Hilo||(t.Hilo={});var e=t.Hilo.Class,i={_listeners:null,on:function(t,e,i){for(var n=this._listeners=this._listeners||{},r=n[t]=n[t]||[],a=0,o=r.length;a-1&&o.splice(c,1)}}return 0==o.length&&delete a[r],!0}return!1}},n=e.create({constructor:function(t,e,i){this.type=t,this.target=e,this.detail=i,this.timeStamp=+new Date},type:null,target:null,detail:null,timeStamp:0,stopImmediatePropagation:function(){this._stopped=!0}}),r=t.Event;if(r){var a=r.prototype,o=a.stopImmediatePropagation;a.stopImmediatePropagation=function(){o&&o.call(this),this._stopped=!0}}t.Hilo.EventMixin=i}(window),function(t){t.Hilo||(t.Hilo={});var e=t.Hilo.Class,i=t.Hilo.util,n=e.create({constructor:function(t){this.init(t)},image:null,rect:null,init:function(t){var e=this,r=e.image;n.isDrawable(t)?e.image=t:i.copy(e,t,!0);var a=e.image;if("string"==typeof a){if(!r||a!==r.getAttribute("src")){e.image=null;var o=new Image;return t.crossOrigin&&(o.crossOrigin="Anonymous"),o.onload=function(){o.onload=null,e.init(o)},void(o.src=a)}a=e.image=r}a&&!e.rect&&(e.rect=[0,0,a.width,a.height])},Statics:{isDrawable:function(t){if(!t||!t.tagName)return!1;var e=t.tagName.toLowerCase();return"img"===e||"canvas"===e||"video"===e}}});t.Hilo.Drawable=n}(window),function(t){t.Hilo||(t.Hilo={});var e=t.Hilo.Class,i=t.Hilo.util,n=e.create({constructor:function(t){t=t||{},i.copy(this,t,!0)},renderType:null,canvas:null,stage:null,blendMode:"source-over",startDraw:function(t){},draw:function(t){},endDraw:function(t){},transform:function(){},hide:function(){},remove:function(t){},clear:function(t,e,i,n){},resize:function(t,e){}});t.Hilo.Renderer=n}(window),function(t){t.Hilo||(t.Hilo={});var e=t.Hilo.Class,i=t.Hilo,n=t.Hilo.Renderer,r=e.create({Extends:n,constructor:function(t){r.superclass.constructor.call(this,t),this.context=this.canvas.getContext("2d")},renderType:"canvas",context:null,startDraw:function(t){return!!(t.visible&&t.alpha>0)&&(t===this.stage&&this.context.clearRect(0,0,t.width,t.height),t.blendMode!==this.blendMode&&(this.context.globalCompositeOperation=this.blendMode=t.blendMode),this.context.save(),!0)},draw:function(t){var e=this.context,i=t.width,n=t.height,r=t.background;r&&(e.fillStyle=r,e.fillRect(0,0,i,n));var a=t.drawable,o=a&&a.image;if(o){var s=a.rect,l=s[2],h=s[3],c=s[4],u=s[5];if(!l||!h)return;i||n||(i=t.width=l,n=t.height=h),(c||u)&&e.translate(c-.5*l,u-.5*h),e.drawImage(o,s[0],s[1],l,h,0,0,i,n)}},endDraw:function(t){this.context.restore()},transform:function(t){var e=t.drawable;if(e&&e.domElement)return void i.setElementStyleByView(t);var n=this.context,r=t.scaleX,a=t.scaleY;if(t===this.stage){var o=this.canvas.style,s=t._scaleX,l=t._scaleY,h=!1;(!s&&1!=r||s&&s!=r)&&(t._scaleX=r,o.width=r*t.width+"px",h=!0),(!l&&1!=a||l&&l!=a)&&(t._scaleY=a,o.height=a*t.height+"px",h=!0),h&&t.updateViewport()}else{var c=t.x,u=t.y,d=t.pivotX,f=t.pivotY,p=t.rotation%360,v=t.transform,m=t.mask;m&&(m._render(this),n.clip());var _=t.align;if(_){var g=t.getAlignPosition();c=g.x,u=g.y}v?n.transform(v.a,v.b,v.c,v.d,v.tx,v.ty):(0==c&&0==u||n.translate(c,u),0!=p&&n.rotate(p*Math.PI/180),1==r&&1==a||n.scale(r,a),0==d&&0==f||n.translate(-d,-f))}t.alpha>0&&(n.globalAlpha*=t.alpha)},remove:function(t){var e=t.drawable,i=e&&e.domElement;if(i){var n=i.parentNode;n&&n.removeChild(i)}},clear:function(t,e,i,n){this.context.clearRect(t,e,i,n)},resize:function(t,e){var i=this.canvas,n=this.stage,r=i.style;i.width=t,i.height=e,r.width=n.width*n.scaleX+"px",r.height=n.height*n.scaleY+"px"}});t.Hilo.CanvasRenderer=r}(window),function(t){t.Hilo||(t.Hilo={});var e=t.Hilo.Class,i=t.Hilo,n=t.Hilo.Renderer,r=t.Hilo.Drawable,a=function(){function t(t,e){var n=t.tagName||"div",r=e.image,a=t.width||r&&r.width,o=t.height||r&&r.height,s=i.createElement(n),l=s.style;if(t.id&&(s.id=t.id),l.position="absolute",l.left=(t.left||0)+"px",l.top=(t.top||0)+"px",l.width=a+"px",l.height=o+"px","canvas"==n){if(s.width=a,s.height=o,r){var h=s.getContext("2d"),c=e.rect||[0,0,a,o];h.drawImage(r,c[0],c[1],c[2],c[3],t.x||0,t.y||0,t.width||c[2],t.height||c[3])}}else if(l.opacity=void 0!=t.alpha?t.alpha:1,(t===this.stage||t.clipChildren)&&(l.overflow="hidden"),r&&r.src){l.backgroundImage="url("+r.src+")";var u=t.rectX||0,d=t.rectY||0;l.backgroundPosition=-u+"px "+-d+"px"}return s}return e.create({Extends:n,constructor:function(t){a.superclass.constructor.call(this,t)},renderType:"dom",startDraw:function(e){var i=e.drawable=e.drawable||new r;return i.domElement=i.domElement||t(e,i),!0},draw:function(t){var e=t.parent,i=t.drawable.domElement,n=i.parentNode;if(e){var r=e.drawable.domElement;if(r!=n&&r.appendChild(i),!t.width&&!t.height){var a=t.drawable.rect;a&&(a[2]||a[3])&&(t.width=a[2],t.height=a[3])}}else t!==this.stage||n||(i.style.overflow="hidden",this.canvas.appendChild(i))},transform:function(t){if(i.setElementStyleByView(t),t===this.stage){var e=this.canvas.style,n=t._scaleX,r=t._scaleY,a=t.scaleX,o=t.scaleY;(!n&&1!=a||n&&n!=a)&&(t._scaleX=a,e.width=a*t.width+"px"),(!r&&1!=o||r&&r!=o)&&(t._scaleY=o,e.height=o*t.height+"px")}},remove:function(t){var e=t.drawable,i=e&&e.domElement;if(i){var n=i.parentNode;n&&n.removeChild(i)}},hide:function(t){var e=t.drawable&&t.drawable.domElement;e&&(e.style.display="none")},resize:function(t,e){var i=this.canvas.style;i.width=t+"px",i.height=e+"px","absolute"!=i.position&&(i.position="relative")}})}();t.Hilo.DOMRenderer=a}(window),function(t){t.Hilo||(t.Hilo={});var e=t.Hilo.Class,i=t.Hilo,n=t.Hilo.Renderer,r=t.Hilo.Matrix,a=Math.PI/180,o=e.create({Extends:n,Statics:{MAX_BATCH_NUM:2e3,ATTRIBUTE_NUM:5,isSupport:function(){if(void 0==this._isSupported){var t=document.createElement("canvas");t.getContext&&(t.getContext("webgl")||t.getContext("experimental-webgl"))?this._isSupported=!0:this._isSupported=!1}return this._isSupported},contextOptions:null},renderType:"webgl",gl:null,_isContextLost:!1,_cacheTexture:{},constructor:function(t){o.superclass.constructor.call(this,t);var e=this,i=o.contextOptions||{};this.gl=this.canvas.getContext("webgl",i)||this.canvas.getContext("experimental-webgl",i),this.maxBatchNum=o.MAX_BATCH_NUM,this.positionStride=4*o.ATTRIBUTE_NUM;var n=this.maxBatchNum*o.ATTRIBUTE_NUM*4,r=6*this.maxBatchNum;this.arrayBuffer=new ArrayBuffer(4*n),this.float32Array=new Float32Array(this.arrayBuffer),this.uint32Array=new Uint32Array(this.arrayBuffer),this.indexs=new Uint16Array(r);for(var a=0,s=0;a0)&&(t===this.stage&&this.clear(),!0)},draw:function(t){var e=t.width,i=t.height,n=(t.background,t.drawable),r=n&&n.image;if(r){var a=n.rect,o=a[2],s=a[3];e||i||(e=t.width=o,i=t.height=s),this.batchIndex>=this.maxBatchNum&&this._renderBatches();var l=this._createVertexs(r,a[0],a[1],o,s,0,0,e,i),h=this.batchIndex*this.positionStride,c=this.float32Array,u=this.uint32Array,d=(t.tint>>16)+(65280&t.tint)+((255&t.tint)<<16)+(255*t.__webglRenderAlpha<<24);c[h+0]=l[0],c[h+1]=l[1],c[h+2]=l[2],c[h+3]=l[3],u[h+4]=d,c[h+5]=l[4],c[h+6]=l[5],c[h+7]=l[6],c[h+8]=l[7],u[h+9]=d,c[h+10]=l[8],c[h+11]=l[9],c[h+12]=l[10],c[h+13]=l[11],u[h+14]=d,c[h+15]=l[12],c[h+16]=l[13],c[h+17]=l[14],c[h+18]=l[15],u[h+19]=d;for(var f=t.__webglWorldMatrix,p=0;p<4;p++){var v=c[h+5*p],m=c[h+5*p+1];c[h+5*p]=f.a*v+f.c*m+f.tx,c[h+5*p+1]=f.b*v+f.d*m+f.ty}t.__textureImage=r,this.sprites[this.batchIndex++]=t}},endDraw:function(t){t===this.stage&&this._renderBatches()},transform:function(t){var e=t.drawable;if(e&&e.domElement)return void i.setElementStyleByView(t);var n=t.scaleX,a=t.scaleY;if(t===this.stage){var o=this.canvas.style,s=t._scaleX,l=t._scaleY,h=!1;(!s&&1!=n||s&&s!=n)&&(t._scaleX=n,o.width=n*t.width+"px",h=!0),(!l&&1!=a||l&&l!=a)&&(t._scaleY=a,o.height=a*t.height+"px",h=!0),h&&t.updateViewport(),t.__webglWorldMatrix=t.__webglWorldMatrix||new r(1,0,0,1,0,0)}else t.parent&&(t.__webglWorldMatrix=t.__webglWorldMatrix||new r(1,0,0,1,0,0),this._setConcatenatedMatrix(t,t.parent));t.alpha>0&&(t.parent&&t.parent.__webglRenderAlpha?t.__webglRenderAlpha=t.alpha*t.parent.__webglRenderAlpha:t.__webglRenderAlpha=t.alpha)},remove:function(t){var e=t.drawable,i=e&&e.domElement;if(i){var n=i.parentNode;n&&n.removeChild(i)}},clear:function(t,e,i,n){this.gl.clear(this.gl.COLOR_BUFFER_BIT)},resize:function(t,e){if(this.width!==t||this.height!==e){var i=this.canvas,n=this.stage,r=i.style;this.width=i.width=t,this.height=i.height=e,r.width=n.width*n.scaleX+"px",r.height=n.height*n.scaleY+"px",this.gl.viewport(0,0,t,e),this.canvasHalfWidth=.5*t,this.canvasHalfHeight=.5*e,this._uploadProjectionTransform(!0)}},_renderBatches:function(){var t=this.gl;t.bufferSubData(t.ARRAY_BUFFER,0,this.uint32Array.subarray(0,this.batchIndex*this.positionStride));for(var e=0,i=0,n=null,r=0;r0&&(i.bindTexture(i.TEXTURE_2D,this._getTexture(this.sprites[t])),i.drawElements(i.TRIANGLES,6*n,i.UNSIGNED_SHORT,6*t*2))},_uploadProjectionTransform:function(t){this._projectionTransformElements&&!t||(this._projectionTransformElements=new Float32Array([1/this.canvasHalfWidth,0,0,0,-1/this.canvasHalfHeight,0,-1,1,1])),this.gl.uniformMatrix3fv(this.u_projectionTransform,!1,this._projectionTransformElements)},_initShaders:function(){var t=" attribute vec2 a_position;\n attribute vec2 a_TexCoord;\n attribute vec4 a_tint;\n uniform mat3 u_projectionTransform;\n varying vec2 v_TexCoord;\n varying vec4 v_tint;\n void main(){\n gl_Position = vec4((u_projectionTransform * vec3(a_position, 1.0)).xy, 1.0, 1.0);\n v_TexCoord = a_TexCoord;\n v_tint = vec4(a_tint.rgb * a_tint.a, a_tint.a);\n }\n ",e="\n precision mediump float;\n uniform sampler2D u_Sampler;\n varying vec2 v_TexCoord;\n varying vec4 v_tint;\n void main(){\n gl_FragColor = texture2D(u_Sampler, v_TexCoord) * v_tint;\n }\n ";this.defaultShader=new s(this,{v:t,f:e},{attributes:["a_position","a_TexCoord","a_tint"],uniforms:["u_projectionTransform","u_Sampler"]})},_createVertexs:function(t,e,i,n,r,a,o,s,l){var h=this.__tempVertexs||[],c=t.width,u=t.height;n/=c,r/=u,e/=c,i/=u,s=s,l=l,a=a,o=o,n+e>1&&(n=1-e),r+i>1&&(r=1-i);var d=0;return h[d++]=a,h[d++]=o,h[d++]=e,h[d++]=i,h[d++]=a+s,h[d++]=o,h[d++]=e+n,h[d++]=i,h[d++]=a,h[d++]=o+l,h[d++]=e,h[d++]=i+r,h[d++]=a+s,h[d++]=o+l,h[d++]=e+n,h[d++]=i+r,h},_setConcatenatedMatrix:function(t,e){var i=t.__webglWorldMatrix,n=1,r=0,o=t.rotation%360,s=t.pivotX,l=t.pivotY,h=t.scaleX,c=t.scaleY,u=t.transform;if(u)i.copy(u);else{if(o){var d=o*a;n=Math.cos(d),r=Math.sin(d)}var f=t.getAlignPosition();i.a=n*h,i.b=r*h,i.c=-r*c,i.d=n*c,i.tx=f.x-i.a*s-i.c*l,i.ty=f.y-i.b*s-i.d*l}i.concat(e.__webglWorldMatrix)},_getTexture:function(t){var e=t.__textureImage,i=this._cacheTexture[e.src];return i||(i=this.activeShader.uploadTexture(e)),i}}),s=function(t,e,i){this.renderer=t,this.gl=t.gl,this.program=this._createProgram(this.gl,e.v,e.f),i=i||{},this.attributes=i.attributes||[],this.uniforms=i.uniforms||[]};s.prototype={active:function(){var t=this,e=t.renderer,i=t.gl,n=t.program;n&&i&&(e.activeShader=t,i.useProgram(n),t.attributes.forEach(function(t){e[t]=i.getAttribLocation(n,t),i.enableVertexAttribArray(e[t])}),t.uniforms.forEach(function(t){e[t]=i.getUniformLocation(n,t)}),t.width===e.width&&t.height===e.height||(t.width=e.width,t.height=e.height,e._uploadProjectionTransform()))},uploadTexture:function(t){var e=this.gl,i=this.renderer,n=e.createTexture(),r=i.u_Sampler;return e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,n),e.pixelStorei(e.UNPACK_PREMULTIPLY_ALPHA_WEBGL,1),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,t),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.uniform1i(r,0),e.bindTexture(e.TEXTURE_2D,null),this.renderer._cacheTexture[t.src]=n,n},_createProgram:function(t,e,i){var n=this._createShader(t,t.VERTEX_SHADER,e),r=this._createShader(t,t.FRAGMENT_SHADER,i);if(!n||!r)return null;var a=t.createProgram();if(a){t.attachShader(a,n),t.attachShader(a,r),t.linkProgram(a),t.deleteShader(r),t.deleteShader(n);var o=t.getProgramParameter(a,t.LINK_STATUS);if(!o){var s=t.getProgramInfoLog(a);return console.log("Failed to link program: "+s),t.deleteProgram(a),null}}return a},_createShader:function(t,e,i){var n=t.createShader(e);if(n){t.shaderSource(n,i),t.compileShader(n);var r=t.getShaderParameter(n,t.COMPILE_STATUS);if(!r){var a=t.getShaderInfoLog(n);return console.log("Failed to compile shader: "+a),t.deleteShader(n),null}}return n}},t.Hilo.WebGLRenderer=o}(window),function(t){t.Hilo||(t.Hilo={});var e=t.Hilo,i=t.Hilo.Class,n=t.Hilo.EventMixin,r=t.Hilo.Matrix,a=t.Hilo.util,o=function(){function t(t,e,i){for(var n,r,a,o,s=0,l=!1,h=0,c=i.length;hd.x?(n=d.x,r=u.x):(n=u.x,r=d.x),t>=n&&t<=r))l=!0;else if(u.y>d.y?(a=d.y,o=u.y):(a=u.y,o=d.y),!(eo)){var f=(e-u.y)*(d.x-u.x)/(d.y-u.y)+u.x;if(f>t?s++:f==t&&(l=!0),u.x>t&&u.y==e){var p=i[(c+h-1)%c];(p.ye||p.y>e&&d.ys?s=c:ch?h=c:c=0)return!1;u>i.overlap&&(i.overlap=u,i.normal.x=p.x,i.normal.y=p.y)}return i}return i.create({Mixes:n,constructor:function(t){t=t||{},this.id=this.id||t.id||e.getUid("View"),a.copy(this,t,!0)},tint:16777215,id:null,x:0,y:0,width:0,height:0,alpha:1,rotation:0,visible:!0,pivotX:0,pivotY:0,scaleX:1,scaleY:1,pointerEnabled:!0,background:null,mask:null,align:null,drawable:null,boundsArea:null,parent:null,depth:-1,transform:null,blendMode:"source-over",getStage:function(){for(var t,e=this;t=e.parent;)e=t;return e.canvas?e:null},getScaledWidth:function(){return this.width*this.scaleX},getScaledHeight:function(){return this.height*this.scaleY},addTo:function(t,e){return"number"==typeof e?t.addChildAt(this,e):t.addChild(this),this},removeFromParent:function(){var t=this.parent;return t&&t.removeChild(this),this},getBounds:function(){for(var t,e,i,n,r,a,o,s=this.width,l=this.height,h=this.getConcatenatedMatrix(),c=this.boundsArea||[{x:0,y:0},{x:s,y:0},{x:s,y:l},{x:0,y:l}],u=[],d=0,f=c.length;de?n=e:ri?a=i:o>1,n=0;break;case"TR":i=o-r,n=0;break;case"L":i=0,n=s-a>>1;break;case"C":i=o-r>>1,n=s-a>>1;break;case"R":i=o-r,n=s-a>>1;break;case"BL":i=0,n=s-a;break;case"B":i=o-r>>1,n=s-a;break;case"BR":i=o-r,n=s-a}}return{x:i,y:n}},hitTestPoint:function(e,i,n){var r=this.getBounds(),a=e>=r.x&&e<=r.x+r.width&&i>=r.y&&i<=r.y+r.height;return a&&n&&(a=t(e,i,r)),a},hitTestObject:function(t,e){var i=this.getBounds(),n=t.getBounds(),r=i.x<=n.x+n.width&&n.x<=i.x+i.width&&i.y<=n.y+n.height&&n.y<=i.y+i.height;return r&&e&&(r=o(i,n)),!!r},_render:function(t,e){this.onUpdate&&this.onUpdate(e)===!1||!t.startDraw(this)||(t.transform(this),this.render(t,e),t.endDraw(this))},_fireMouseEvent:function(t){if(t.eventCurrentTarget=this,this.fire(t),"mousemove"==t.type){if(!this.__mouseOver){this.__mouseOver=!0;var e=a.copy({},t);e.type="mouseover",this.fire(e)}}else"mouseout"==t.type&&(this.__mouseOver=!1);var i=this.parent;t._stopped||t._stopPropagationed||!i||("mouseout"==t.type||"touchout"==t.type?i.hitTestPoint(t.stageX,t.stageY,!0)||i._fireMouseEvent(t):i._fireMouseEvent(t))},onUpdate:null,render:function(t,e){t.draw(this)},toString:function(){return e.viewToString(this)}})}();t.Hilo.View=o}(window),function(t){t.Hilo||(t.Hilo={});var e,i,n=t.Hilo.Drawable,r=t.Hilo.browser,a={_cacheDirty:!0,cache:function(t){(t||this._cacheDirty||!this.drawable)&&this.updateCache()},updateCache:function(){r.supportCanvas&&(e||(e=document.createElement("canvas"),i=e.getContext("2d")),e.width=this.width,e.height=this.height,this._draw(i),this.drawable=this.drawable||new n,this.drawable.init({image:e.toDataURL()}),this._cacheDirty=!1)},setCacheDirty:function(t){this._cacheDirty=t}};t.Hilo.CacheMixin=a}(window),function(t){t.Hilo||(t.Hilo={});var e=t.Hilo,i=t.Hilo.Class,n=t.Hilo.View,r=i.create({Extends:n,constructor:function(t){t=t||{},this.id=this.id||t.id||e.getUid("Container"),r.superclass.constructor.call(this,t),this.children?this._updateChildren():this.children=[]},children:null,pointerChildren:!0,clipChildren:!1,getNumChildren:function(){return this.children.length},addChildAt:function(t,e){var i=this.children,n=i.length,r=t.parent;e=e<0?0:e>n?n:e;var a=this.getChildIndex(t);if(a==e)return this;if(a>=0?(i.splice(a,1),e=e==n?n-1:e):r&&r.removeChild(t),i.splice(e,0,t),a<0)this._updateChildren(e);else{var o=a=e.length)return null;var i=e[t];if(i){if(!i.__renderer)for(var n=i;n=n.parent;){if(n.renderer){i.__renderer=n.renderer;break}if(n.__renderer){i.__renderer=n.__renderer;break}}i.__renderer&&i.__renderer.remove(i),i.parent=null,i.depth=-1}return e.splice(t,1),this._updateChildren(t),i},removeChild:function(t){return this.removeChildAt(this.getChildIndex(t))},removeChildById:function(t){for(var e,i=this.children,n=0,r=i.length;n=e.length?null:e[t]},getChildById:function(t){for(var e,i=this.children,n=0,r=i.length;n=0&&n!=e){var r=i.length;e=e<0?0:e>=r?r-1:e,i.splice(n,1),i.splice(e,0,t),this._updateChildren()}return this},swapChildren:function(t,e){var i=this.children,n=this.getChildIndex(t),r=this.getChildIndex(e);t.depth=r,i[r]=t,e.depth=n,i[n]=e},swapChildrenAt:function(t,e){var i=this.children,n=this.getChildAt(t),r=this.getChildAt(e);n.depth=e,i[e]=n,r.depth=t,i[t]=r},sortChildren:function(t){var e=t,i=this.children;if("string"==typeof e){var n=e;e=function(t,e){return e[n]-t[n]}}i.sort(e),this._updateChildren()},_updateChildren:function(t,e){var i,n=this.children;t=t||0,e=e||n.length;for(var r=t;r=0;h--)if(a=l[h],!(!a||!a.visible||a.alpha<=0||r&&!a.pointerEnabled))if(a.children&&a.children.length&&(!r||a.pointerChildren)&&(o=a.getViewAtPoint(t,e,i,n,r)),o){if(!n)return o;o.length&&(s=s.concat(o))}else if(a.hitTestPoint(t,e,i)){if(!n)return a;s.push(a)}return n&&s.length?s:null},render:function(t,e){r.superclass.render.call(this,t,e);var i,n,a,o=this.children.slice(0);for(i=0,n=o.length;in?n:e,i[e]=t,t.name&&(this._frameNames[t.name]=t),(0!=e||this.width)&&this.height||(this.width=t.rect[2],this.height=t.rect[3]),this},getFrame:function(t){if("number"==typeof t){var e=this._frames;return t<0||t>=e.length?null:e[t]}return this._frameNames[t]},getFrameIndex:function(t){var e=this._frames,i=e.length,n=-1;if("number"==typeof t)n=t;else{var r="string"==typeof t?this._frameNames[t]:t;if(r)for(var a=0;a=i?i-1:n,this.paused=e,this._firstRender=!0,this},_render:function(t,e){var i,n=this.currentFrame;if(this._firstRender?(i=n,this._firstRender=!1):i=this._nextFrame(e),i!=n){this.currentFrame=i;var r=this._frames[i].callback;r&&r.call(this)}this.onEnterFrame&&this.onEnterFrame(i),this.drawable.init(this._frames[i]),a.superclass._render.call(this,t,e)},_nextFrame:function(t){var e=this._frames,i=e.length,n=this.currentFrame,r=e[n],a=r.duration||this.interval,o=this._frameElapsed,s=0!=n||this.drawable?o+(this.timeBased?t:1):0;return o=this._frameElapsed=s=i-1)&&this.stop(),this.paused||0!=o||(null!=r.next?n=this.getFrameIndex(r.next):n>=i-1?n=0:this.drawable&&n++),n},setFrameCallback:function(t,e){return t=this.getFrame(t),t&&(t.callback=e),this},onEnterFrame:null});t.Hilo.Sprite=a}(window),function(t){t.Hilo||(t.Hilo={});var e=t.Hilo,i=t.Hilo.Class,n=t.Hilo.View,r=t.Hilo.Drawable,a=i.create({Extends:n,constructor:function(t){t=t||{},this.id=this.id||t.id||e.getUid("DOMElement"),a.superclass.constructor.call(this,t),this.drawable=new r;var i=this.drawable.domElement=t.element||e.createElement("div");i.id=this.id,this.pointerEnabled&&!i.style.pointerEvents&&(i.style.pointerEvents="visible")},_render:function(t,e){this.onUpdate&&this.onUpdate(e)===!1||(t.transform(this),this.visible&&this.alpha>0&&this.render(t,e))},render:function(t,i){if("dom"!==t.renderType){var n=t.canvas,r=this.parent,a=t._domElementContainer;t._domElementContainer||(a=t._domElementContainer=e.createElement("div",{style:{position:"absolute",transform:"scale3d("+r.scaleX+","+r.scaleY+", 1)",transformOrigin:"0 0",zIndex:"1"}}),n.parentNode.insertBefore(t._domElementContainer,n.nextSibling));var o,s=this.drawable.domElement,l=this.depth,h=a.childNodes[0];if(s.parentNode)return;for(;h&&3!=h.nodeType&&(o=parseInt(h.style.zIndex)||0,!(o<=0||o>l));)h=h.nextSibling;a.insertBefore(this.drawable.domElement,h)}else t.draw(this)}});t.Hilo.DOMElement=a}(window),function(t){t.Hilo||(t.Hilo={});var e=t.Hilo,i=t.Hilo.Class,n=t.Hilo.View,r=t.Hilo.CacheMixin,a=function(){var t=document.createElement("canvas"),o=t.getContext&&t.getContext("2d");return i.create({Extends:n,Mixes:r,constructor:function(t){t=t||{},this.id=this.id||t.id||e.getUid("Graphics"),a.superclass.constructor.call(this,t),this._actions=[]},lineWidth:1,lineAlpha:1,lineCap:null,lineJoin:null,miterLimit:10,hasStroke:!1,strokeStyle:"0",hasFill:!1,fillStyle:"0",fillAlpha:0,lineStyle:function(t,e,i,n,r,a){var o=this,s=o._addAction;return s.call(o,["lineWidth",o.lineWidth=t||1]),s.call(o,["strokeStyle",o.strokeStyle=e||"0"]),s.call(o,["lineAlpha",o.lineAlpha=i||1]),void 0!=n&&s.call(o,["lineCap",o.lineCap=n]),void 0!=r&&s.call(o,["lineJoin",o.lineJoin=r]),void 0!=a&&s.call(o,["miterLimit",o.miterLimit=a]),o.hasStroke=!0,o},setLineDash:function(t){return this._addAction(["setLineDash",t])},beginFill:function(t,e){var i=this,n=i._addAction;return n.call(i,["fillStyle",i.fillStyle=t]),n.call(i,["fillAlpha",i.fillAlpha=e||1]),i.hasFill=!0,i},endFill:function(){var t=this,e=t._addAction;return t.hasStroke&&e.call(t,["stroke"]),t.hasFill&&e.call(t,["fill"]),t.setCacheDirty(!0),t},beginLinearGradientFill:function(t,e,i,n,r,a){for(var s=this,l=o.createLinearGradient(t,e,i,n),h=0,c=r.length;h1?a.slice(1):null;"function"==typeof t[o]?t[o].apply(t,s):t[o]=a[1]}},render:function(t,e){var i=this;"canvas"===t.renderType?i._draw(t.context):(i.cache(),t.draw(i))},clear:function(){var t=this;return t._actions.length=0,t.lineWidth=1,t.lineAlpha=1,t.lineCap=null,t.lineJoin=null,t.miterLimit=10,t.hasStroke=!1,t.strokeStyle="0",t.hasFill=!1,t.fillStyle="0",t.fillAlpha=1,t.setCacheDirty(!0),t},_addAction:function(t){var e=this;return e._actions.push(t),e}})}();t.Hilo.Graphics=a}(window),function(t){t.Hilo||(t.Hilo={});var e=t.Hilo.Class,i=t.Hilo,n=t.Hilo.View,r=t.Hilo.CacheMixin,a=e.create({Extends:n,Mixes:r,constructor:function(t){t=t||{},this.id=this.id||t.id||i.getUid("Text"),a.superclass.constructor.call(this,t),t.font||(this.font="12px arial"),this._fontHeight=a.measureFontHeight(this.font)},text:"",color:"#000",textAlign:null,textVAlign:null,outline:!1,lineSpacing:0,maxWidth:200,font:null,textWidth:0,textHeight:0,setFont:function(t){var e=this;return e.font!==t&&(e.font=t,e._fontHeight=a.measureFontHeight(t)),e},render:function(t,e){var i=this;if("canvas"===t.renderType)this.drawable?t.draw(i):i._draw(t.context);else if("dom"===t.renderType){var n=i.drawable,r=n.domElement,a=r.style;a.font=i.font,a.textAlign=i.textAlign,a.color=i.color,a.width=i.width+"px",a.height=i.height+"px",a.lineHeight=i._fontHeight+i.lineSpacing+"px",r.innerHTML=i.text,t.draw(this)}else i.cache(),t.draw(i)},_draw:function(t){var e=this,i=e.text.toString();if(i){t.font=e.font,t.textAlign=e.textAlign,t.textBaseline="top";var n,r,a,o,s,l=i.split(/\r\n|\r|\n|/),h=0,c=0,u=e._fontHeight+e.lineSpacing,d=[];for(n=0,o=l.length;ne.maxWidth?(d.push({text:m,y:c}),h<_&&(h=_),c+=u,m=v):(_=f,m+=v),p==s-1&&(d.push({text:m,y:c}),m!==v&&h>1;break;case"bottom":g=e.height-e.textHeight}var x=e.background;for(x&&(t.fillStyle=x,t.fillRect(0,0,e.width,e.height)),e.outline?t.strokeStyle=e.color:t.fillStyle=e.color,n=0;n>1;break;case"right":case"end":r=a}n.outline?t.strokeText(e,r,i):t.fillText(e,r,i)},Statics:{measureFontHeight:function(t){var e,n=document.documentElement,r=i.createElement("div",{style:{font:t,position:"absolute"},innerHTML:"M"});return n.appendChild(r),e=r.offsetHeight,n.removeChild(r),e}}});t.Hilo.Text=a}(window),function(t){t.Hilo||(t.Hilo={});var e=t.Hilo.Class,i=t.Hilo,n=t.Hilo.Container,r=t.Hilo.Bitmap,a=e.create({Extends:n,constructor:function(t){t=t||{},this.id=this.id||t.id||i.getUid("BitmapText"),a.superclass.constructor.call(this,t);var e=t.text+"";e&&(this.text="",this.setText(e)),this.pointerChildren=!1},glyphs:null,letterSpacing:0,text:"",textAlign:"left",setText:function(t){var e=this,i=t.toString(),n=i.length;if(e.text!=i){e.text=i;var r,a,o,s,l=0,h=0,c=0;for(r=0;r0?e.letterSpacing:0),e.children[r]?(s=e.children[r],s.setImage(o.image,o.rect)):(s=e._createBitmap(o),e.addChild(s)),s.x=c,l=c+o.rect[2],h=Math.max(h,o.rect[3]));for(r=e.children.length-1;r>=n;r--)e._releaseBitmap(e.children[r]),e.children[r].removeFromParent();return e.width=l,e.height=h,this.setTextAlign(),e}},_createBitmap:function(t){var e;return a._pool.length?(e=a._pool.pop(),e.setImage(t.image,t.rect)):e=new r({image:t.image,rect:t.rect}),e},_releaseBitmap:function(t){a._pool.push(t)},setTextAlign:function(t){switch(this.textAlign=t||this.textAlign,this.textAlign){case"center":this.pivotX=.5*this.width;break;case"right":this.pivotX=this.width;break;case"left":default:this.pivotX=0}return this},hasGlyphs:function(t){var e=this.glyphs;if(!e)return!1;t=t.toString();var i,n=t.length;for(i=0;i=this._targetFPS?(this._measuredFPS=1e3/(this._tickTime/this._tickCount)+.5>>0,this._tickCount=0,this._tickTime=0):this._tickTime+=t-this._lastTime,this._lastTime=t;for(var n=i.slice(0),r=0,a=n.length;r=0&&e.splice(i,1)},nextTick:function(t){var e=this,i={tick:function(n){e.removeTick(i),t()}};return e.addTick(i),i},timeout:function(t,e){var i=this,n=(new Date).getTime()+e,r={tick:function(){var e=(new Date).getTime(),a=e-n;a>=0&&(i.removeTick(r),t())}};return i.addTick(r),r},interval:function(t,e){var i=this,n=(new Date).getTime()+e,r={tick:function(){var i=(new Date).getTime(),r=i-n;r>=0&&(r=n)return-1;for(e<0&&(e=n+e),i=e;i=1?1:s;var h=r.ease?r.ease(s):s;r.reverse&&r.isStart&&(r._reverseFlag<0&&(s=1-s,h=1-h),s<1e-7&&(r.repeat>0&&r._repeatCount++>=r.repeat||0==r.repeat&&!r.loop?l=!0:(r._startTime=t(),r._pausedTime=0,r._reverseFlag*=-1))),r.isStart||(r.setProps(r._fromProps,r._toProps),r.isStart=!0,r.onStart&&r.onStart.call(r,r)),r.time=a,r._render(h),(o=r.onUpdate)&&o.call(r,s,r),s>=1&&(r.reverse?(r._startTime=t(),r._pausedTime=0,r._reverseFlag*=-1):r.loop||r.repeat>0&&r._repeatCount++0&&u<=e?(c._render(s),c.time=a,i.add(c)):r.isComplete&&(u<0||u>e)&&c.start()}return r.isComplete?((o=r.onComplete)&&o.call(r,r),!0):void 0}}},Statics:{_tweens:[],tick:function(){var e,n,r=i._tweens,a=r.length;for(n=0;n-1&&r.splice(e,1);else for(e=0;e=i)return void t.fire("complete");if(t._currentIndexe.z})},tick:function(){this.sortZ()}});return o}();t.Hilo.Camera3d=n}(window),function(t){t.Hilo||(t.Hilo={});var e=t.Hilo,i=t.Hilo.Class,n=t.Hilo.View,r=t.Hilo.Container,a=t.Hilo.Drawable,o=t.Hilo.util,s=function(){function t(t,e){return e?t+2*(Math.random()-.5)*e:t}for(var s=["x","y","vx","vy","ax","ay","rotation","rotationV","scale","scaleV","alpha","alphaV","life"],l=[],h=0,c=s.length;h=this._emitTime&&(this._currentRunTime=0,this._emitTime=t(this.emitTime,this.emitTimeVar),this._emit()),this._totalRunTime>=this.totalTime&&this.stop())},_emit:function(){for(var e=t(this.emitNum,this.emitNumVar)>>0,i=0;i=0;e--)this.children[e].destroy()}}),v=i.create({Extends:n,constructor:function(t){this.id=this.id||t.id||e.getUid("Particle"),v.superclass.constructor.call(this,t),this.init(t)},onUpdate:function(t){if(t*=.001,this._died)return!1;var e=this.ax+this.system.gx,i=this.ay+this.system.gy;return this.vx+=e*t,this.vy+=i*t,this.x+=this.vx*t,this.y+=this.vy*t,this.rotation+=this.rotationV,this._time>.1&&(this.alpha+=this.alphaV),this.scale+=this.scaleV,this.scaleX=this.scaleY=this.scale,this._time+=t,this._time>=this.life||this.alpha<=0?(this.destroy(),!1):void 0},setImage:function(t,e){this.drawable=this.drawable||new a,e=e||[0,0,t.width,t.height],this.width=e[2],this.height=e[3],this.drawable.rect=e,this.drawable.image=t},destroy:function(){this._died=!0,this.alpha=0,this.removeFromParent(),f.push(this)},init:function(e){this.system=e.system,this._died=!1,this._time=0,this.alpha=1;for(var i=0,n=l.length;i>0]),this.setImage(e.image,o),void 0!==e.pivotX&&(this.pivotX=e.pivotX*o[2]),void 0!==e.pivotY&&(this.pivotY=e.pivotY*o[3])}},Statics:{create:function(t){if(f.length>0){var e=f.pop();return e.init(t),e}return new v(t)}}});return p}();t.Hilo.ParticleSystem=s}(window); \ No newline at end of file diff --git a/build/standalone/hilo-standalone.zip b/build/standalone/hilo-standalone.zip new file mode 100644 index 00000000..b0f5fe97 Binary files /dev/null and b/build/standalone/hilo-standalone.zip differ diff --git a/build/standalone/hilo/core/Class.js b/build/standalone/hilo/core/Class.js index 4ed43289..acd6c6de 100644 --- a/build/standalone/hilo/core/Class.js +++ b/build/standalone/hilo/core/Class.js @@ -1,5 +1,5 @@ /** - * Hilo 1.5.0 for standalone + * Hilo 1.6.0 for standalone * Copyright 2016 alibaba.com * Licensed under the MIT License */ diff --git a/build/standalone/hilo/core/Class.min.js b/build/standalone/hilo/core/Class.min.js index 58a9ee05..9b509865 100644 --- a/build/standalone/hilo/core/Class.min.js +++ b/build/standalone/hilo/core/Class.min.js @@ -1,186 +1,6 @@ /** - * Hilo 1.5.0 for standalone + * Hilo 1.6.0 for standalone * Copyright 2016 alibaba.com * Licensed under the MIT License */ -/** - * Hilo 1.5.0 for standalone - * Copyright 2016 alibaba.com - * Licensed under the MIT License - */ -(function(window){ -if(!window.Hilo) window.Hilo = {}; - - -/** - * @language=en - * Create Example Class: - *
- * var Bird = Hilo.Class.create({
- *     Extends: Animal,
- *     Mixes: EventMixin,
- *     constructor: function(name){
- *         this.name = name;
- *     },
- *     fly: function(){
- *         console.log('I am flying');
- *     },
- *     Statics: {
- *         isBird: function(bird){
- *             return bird instanceof Bird;
- *         }
- *     }
- * });
- *
- * var swallow = new Bird('swallow');
- * swallow.fly();
- * Bird.isBird(swallow);
- * 
- * @namespace Class Class is created to aid the developer. - * @static - * @module hilo/core/Class - */ -var Class = (function(){ - -/** - * @language=en - * Create a class based on the parameters, properties and methods specified. - * @param {Object} properties Properties and methods to create the class. - *
    - *
  • Extends - Designed to inherit the parent class.
  • - *
  • Mixes - Specifies mixed member collection object.
  • - *
  • Statics - Static property or method specified class.
  • - *
  • constructor - The constructor of specified class.
  • - *
  • Other members of the property or method to create the class.
  • - *
- * @returns {Object} Create classes. - */ -var create = function(properties){ - properties = properties || {}; - var clazz = properties.hasOwnProperty('constructor') ? properties.constructor : function(){}; - implement.call(clazz, properties); - return clazz; -}; - -/** - * @language=en - * @private - */ -var implement = function(properties){ - var proto = {}, key, value; - for(key in properties){ - value = properties[key]; - if(classMutators.hasOwnProperty(key)){ - classMutators[key].call(this, value); - }else{ - proto[key] = value; - } - } - - mix(this.prototype, proto); -}; - -var classMutators = /** @ignore */{ - Extends: function(parent){ - var existed = this.prototype, proto = createProto(parent.prototype); - //inherit static properites - mix(this, parent); - //keep existed properties - mix(proto, existed); - //correct constructor - proto.constructor = this; - //prototype chaining - this.prototype = proto; - //shortcut to parent's prototype - this.superclass = parent.prototype; - }, - - Mixes: function(items){ - items instanceof Array || (items = [items]); - var proto = this.prototype, item; - - while(item = items.shift()){ - mix(proto, item.prototype || item); - } - }, - - Statics: function(properties){ - mix(this, properties); - } -}; - -/** - * @language=en - * @private - */ -var createProto = (function(){ - if(Object.__proto__){ - return function(proto){ - return {__proto__: proto}; - }; - }else{ - var Ctor = function(){}; - return function(proto){ - Ctor.prototype = proto; - return new Ctor(); - }; - } -})(); - -/** - * @language=en - * Mixed property or method. - * @param {Object} target Mixed audiences. - * @param {Object} source The source whose methods and properties are to be mixed. It can support multiple source parameters. - * @returns {Object} Mixed audiences. - */ -var mix = function(target){ - for(var i = 1, len = arguments.length; i < len; i++){ - var source = arguments[i], defineProps; - for(var key in source){ - var prop = source[key]; - if(prop && typeof prop === 'object'){ - if(prop.value !== undefined || typeof prop.get === 'function' || typeof prop.set === 'function'){ - defineProps = defineProps || {}; - defineProps[key] = prop; - continue; - } - } - target[key] = prop; - } - if(defineProps) defineProperties(target, defineProps); - } - - return target; -}; - -var defineProperty, defineProperties; -try{ - defineProperty = Object.defineProperty; - defineProperties = Object.defineProperties; - defineProperty({}, '$', {value:0}); -}catch(e){ - if('__defineGetter__' in Object){ - defineProperty = function(obj, prop, desc){ - if('value' in desc) obj[prop] = desc.value; - if('get' in desc) obj.__defineGetter__(prop, desc.get); - if('set' in desc) obj.__defineSetter__(prop, desc.set); - return obj; - }; - defineProperties = function(obj, props){ - for(var prop in props){ - if(props.hasOwnProperty(prop)){ - defineProperty(obj, prop, props[prop]); - } - } - return obj; - }; - } -} - -return {create:create, mix:mix}; - -})(); - -window.Hilo.Class = Class; -})(window); \ No newline at end of file +!function(t){t.Hilo||(t.Hilo={});var r=function(){var t,r,n=function(t){t=t||{};var r=t.hasOwnProperty("constructor")?t.constructor:function(){};return e.call(r,t),r},e=function(t){var r,n,e={};for(r in t)n=t[r],o.hasOwnProperty(r)?o[r].call(this,n):e[r]=n;c(this.prototype,e)},o={Extends:function(t){var r=this.prototype,n=i(t.prototype);c(this,t),c(n,r),n.constructor=this,this.prototype=n,this.superclass=t.prototype},Mixes:function(t){t instanceof Array||(t=[t]);for(var r,n=this.prototype;r=t.shift();)c(n,r.prototype||r)},Statics:function(t){c(this,t)}},i=function(){if(Object.__proto__)return function(t){return{__proto__:t}};var t=function(){};return function(r){return t.prototype=r,new t}}(),c=function(t){for(var n=1,e=arguments.length;n= 48 && charCode <= 57) prefix += "_"; //0至9之间添加下划线 - return prefix + id; - } - return id; - }, - - /** - * @language=en - * Generates a string representation that contains a path to the specified visual object. Such as Stage1.Container2.Bitmap3. - * @param {View} view Specified visual object. - * @returns {String} String representation of the visual object. - */ - viewToString: function(view) { - var result, obj = view; - while (obj) { - result = result ? (obj.id + '.' + result) : obj.id; - obj = obj.parent; - } - return result; - }, - - /** - * @language=en - * Simple shallow copy objects. - * @deprecated use Hilo.util.copy instead - * @param {Object} target Target object to copy to. - * @param {Object} source Source object to copy. - * @param {Boolean} strict Indicates whether replication is undefined property, default is false, i.e., undefined attributes are not copied. - * @returns {Object} Object after copying. - */ - copy: function(target, source, strict) { - util.copy(target, source, strict); - if (!hasWarnedDict.copy) { - hasWarnedDict.copy = true; - console.warn('Hilo.copy has been Deprecated! Use Hilo.util.copy instead.'); - } - return target; - }, - - /** - * @language=en - * Browser feature set includes: - * @see browser - */ - browser: browser, - - /** - * @language=en - * Event enumeration objects include: - *
    - *
  • POINTER_START - Mouse or touch start event. Corresponds to touchstart or mousedown.
  • - *
  • POINTER_MOVE - Mouse or touch move event. Corresponds to touchmove or mousemove.
  • - *
  • POINTER_END - Mouse or touch end event. Corresponds to touchend or mouseup.
  • - *
- */ - event: { - POINTER_START: browser.POINTER_START, - POINTER_MOVE: browser.POINTER_MOVE, - POINTER_END: browser.POINTER_END - }, - - /** - * @language=en - * Visual object alinment enumeration objects include: - *
    - *
  • TOP_LEFT - Align the top left corner.
  • - *
  • TOP - Top center alignment.
  • - *
  • TOP_RIGHT - Align the top right corner.
  • - *
  • LEFT - Left center alignment.
  • - *
  • CENTER - Align center.
  • - *
  • RIGHT - Right center alignment.
  • - *
  • BOTTOM_LEFT - Align the bottom left corner.
  • - *
  • BOTTOM - Bottom center alignment.
  • - *
  • BOTTOM_RIGHT - Align the bottom right corner.
  • - *
- */ - align: { - TOP_LEFT: 'TL', //top & left - TOP: 'T', //top & center - TOP_RIGHT: 'TR', //top & right - LEFT: 'L', //left & center - CENTER: 'C', //center - RIGHT: 'R', //right & center - BOTTOM_LEFT: 'BL', //bottom & left - BOTTOM: 'B', //bottom & center - BOTTOM_RIGHT: 'BR' //bottom & right - }, - - /** - * @language=en - * Get DOM element content in the page display area. - * @param {HTMLElement} elem DOM elements. - * @returns {Object} Viewable area DOM elements. Format is: {left:0, top:0, width:100, height:100}. - */ - getElementRect: function(elem) { - var bounds; - try { - //this fails if it's a disconnected DOM node - bounds = elem.getBoundingClientRect(); - } catch (e) { - bounds = { - top: elem.offsetTop, - left: elem.offsetLeft, - right: elem.offsetLeft + elem.offsetWidth, - bottom: elem.offsetTop + elem.offsetHeight - }; - } - - var offsetX = ((win.pageXOffset || docElem.scrollLeft) - (docElem.clientLeft || 0)) || 0; - var offsetY = ((win.pageYOffset || docElem.scrollTop) - (docElem.clientTop || 0)) || 0; - var styles = win.getComputedStyle ? getComputedStyle(elem) : elem.currentStyle; - var parseIntFn = parseInt; - - var padLeft = (parseIntFn(styles.paddingLeft) + parseIntFn(styles.borderLeftWidth)) || 0; - var padTop = (parseIntFn(styles.paddingTop) + parseIntFn(styles.borderTopWidth)) || 0; - var padRight = (parseIntFn(styles.paddingRight) + parseIntFn(styles.borderRightWidth)) || 0; - var padBottom = (parseIntFn(styles.paddingBottom) + parseIntFn(styles.borderBottomWidth)) || 0; - - var top = bounds.top || 0; - var left = bounds.left || 0; - var right = bounds.right || 0; - var bottom = bounds.bottom || 0; - - return { - left: left + offsetX + padLeft, - top: top + offsetY + padTop, - width: right - padRight - left - padLeft, - height: bottom - padBottom - top - padTop - }; - }, - - /** - * @language=en - * Create a DOM element. You can specify properties and styles. - * @param {String} type DOM element type to be created. Such as: 'div'. - * @param {Object} properties Properties and styles for DOM element. - * @returns {HTMLElement} A DOM element. - */ - createElement: function(type, properties) { - var elem = doc.createElement(type), - p, val, s; - for (p in properties) { - val = properties[p]; - if (p === 'style') { - for (s in val) elem.style[s] = val[s]; - } else { - elem[p] = val; - } - } - return elem; - }, - - /** - * @language=en - * Gets a DOM element according to the parameter id. This method is equivalent to document.getElementById(id). - * @param {String} id id of the DOM element you want to get. - * @returns {HTMLElement} A DOM element. - */ - getElement: function(id) { - return doc.getElementById(id); - }, - - /** - * @language=en - * Set visual object DOM element CSS style. - * @param {View} obj Specifies the CSS style to set the visual object. - * @private - */ - setElementStyleByView: function(obj) { - var drawable = obj.drawable, - style = drawable.domElement.style, - stateCache = obj._stateCache || (obj._stateCache = {}), - prefix = Hilo.browser.jsVendor, - px = 'px', - flag = false; - - if (this.cacheStateIfChanged(obj, ['visible'], stateCache)) { - style.display = !obj.visible ? 'none' : ''; - } - if (this.cacheStateIfChanged(obj, ['alpha'], stateCache)) { - style.opacity = obj.alpha; - } - if (!obj.visible || obj.alpha <= 0) return; - - if (this.cacheStateIfChanged(obj, ['width'], stateCache)) { - style.width = obj.width + px; - } - if (this.cacheStateIfChanged(obj, ['height'], stateCache)) { - style.height = obj.height + px; - } - if (this.cacheStateIfChanged(obj, ['depth'], stateCache)) { - style.zIndex = obj.depth + 1; - } - if (obj.transform){ - var transform = obj.transform; - if (flag = this.cacheStateIfChanged(obj, ['pivotX', 'pivotY'], stateCache)) { - style[prefix + 'TransformOrigin'] = '0 0'; - } - style[prefix + 'Transform'] = 'matrix3d(' + transform.a + ', '+ transform.b + ', 0, 0, '+ transform.c + ', '+ transform.d + ', 0, 0, 0, 0, 1, 0, '+ transform.tx + ', '+ transform.ty + ', 0, 1)'; - } - else{ - if (flag = this.cacheStateIfChanged(obj, ['pivotX', 'pivotY'], stateCache)) { - style[prefix + 'TransformOrigin'] = obj.pivotX + px + ' ' + obj.pivotY + px; - } - - if (this.cacheStateIfChanged(obj, ['x', 'y', 'rotation', 'scaleX', 'scaleY'], stateCache) || flag) { - style[prefix + 'Transform'] = this.getTransformCSS(obj); - } - } - - if (this.cacheStateIfChanged(obj, ['background'], stateCache)) { - style.backgroundColor = obj.background; - } - if (!style.pointerEvents) { - style.pointerEvents = 'none'; - } - - //render image as background - var image = drawable.image; - if (image) { - var src = image.src; - if (src !== stateCache.image) { - stateCache.image = src; - style.backgroundImage = 'url(' + src + ')'; - } - - var rect = drawable.rect; - if (rect) { - var sx = rect[0], - sy = rect[1]; - if (sx !== stateCache.sx) { - stateCache.sx = sx; - style.backgroundPositionX = -sx + px; - } - if (sy !== stateCache.sy) { - stateCache.sy = sy; - style.backgroundPositionY = -sy + px; - } - } - } - - //render mask - var mask = obj.mask; - if (mask) { - var maskImage = mask.drawable.domElement.style.backgroundImage; - if (maskImage !== stateCache.maskImage) { - stateCache.maskImage = maskImage; - style[prefix + 'MaskImage'] = maskImage; - style[prefix + 'MaskRepeat'] = 'no-repeat'; - } - - var maskX = mask.x, - maskY = mask.y; - if (maskX !== stateCache.maskX || maskY !== stateCache.maskY) { - stateCache.maskX = maskX; - stateCache.maskY = maskY; - style[prefix + 'MaskPosition'] = maskX + px + ' ' + maskY + px; - } - } - }, - - /** - * @private - */ - cacheStateIfChanged: function(obj, propNames, stateCache) { - var i, len, name, value, changed = false; - for (i = 0, len = propNames.length; i < len; i++) { - name = propNames[i]; - value = obj[name]; - if (value != stateCache[name]) { - stateCache[name] = value; - changed = true; - } - } - return changed; - }, - - /** - * @language=en - * Generated visual object CSS style transformation. - * @param {View} obj Specifies visual object whose CSS style must be got. - * @returns {String} String representation of the CSS style. - */ - getTransformCSS: function(obj) { - var use3d = this.browser.supportTransform3D, - str3d = use3d ? '3d' : ''; - - return 'translate' + str3d + '(' + (obj.x - obj.pivotX) + 'px, ' + (obj.y - obj.pivotY) + (use3d ? 'px, 0px)' : 'px)') + - 'rotate' + str3d + (use3d ? '(0, 0, 1, ' : '(') + obj.rotation + 'deg)' + - 'scale' + str3d + '(' + obj.scaleX + ', ' + obj.scaleY + (use3d ? ', 1)' : ')'); - } -}; -for(var i in Hilo){window.Hilo[i] = Hilo[i];} -})(window); \ No newline at end of file +!function(t){t.Hilo||(t.Hilo={});var e=t.Hilo.browser,a=t.Hilo.util,o=t,r=document,n=r.documentElement,i=0,s={},c={version:"1.6.0",getUid:function(t){var e=++i;if(t){var a=t.charCodeAt(t.length-1);return a>=48&&a<=57&&(t+="_"),t+e}return e},viewToString:function(t){for(var e,a=t;a;)e=e?a.id+"."+e:a.id,a=a.parent;return e},copy:function(t,e,o){return a.copy(t,e,o),s.copy||(s.copy=!0,console.warn("Hilo.copy has been Deprecated! Use Hilo.util.copy instead.")),t},browser:e,event:{POINTER_START:e.POINTER_START,POINTER_MOVE:e.POINTER_MOVE,POINTER_END:e.POINTER_END},align:{TOP_LEFT:"TL",TOP:"T",TOP_RIGHT:"TR",LEFT:"L",CENTER:"C",RIGHT:"R",BOTTOM_LEFT:"BL",BOTTOM:"B",BOTTOM_RIGHT:"BR"},getElementRect:function(t){var e;try{e=t.getBoundingClientRect()}catch(a){e={top:t.offsetTop,left:t.offsetLeft,right:t.offsetLeft+t.offsetWidth,bottom:t.offsetTop+t.offsetHeight}}var r=(o.pageXOffset||n.scrollLeft)-(n.clientLeft||0)||0,i=(o.pageYOffset||n.scrollTop)-(n.clientTop||0)||0,s=o.getComputedStyle?getComputedStyle(t):t.currentStyle,c=parseInt,f=c(s.paddingLeft)+c(s.borderLeftWidth)||0,h=c(s.paddingTop)+c(s.borderTopWidth)||0,d=c(s.paddingRight)+c(s.borderRightWidth)||0,l=c(s.paddingBottom)+c(s.borderBottomWidth)||0,g=e.top||0,p=e.left||0,m=e.right||0,T=e.bottom||0;return{left:p+r+f,top:g+i+h,width:m-d-p-f,height:T-l-g-h}},createElement:function(t,e){var a,o,n,i=r.createElement(t);for(a in e)if(o=e[a],"style"===a)for(n in o)i.style[n]=o[n];else i[a]=o;return i},getElement:function(t){return r.getElementById(t)},setElementStyleByView:function(t){var e=t.drawable,a=e.domElement.style,o=t._stateCache||(t._stateCache={}),r=c.browser.jsVendor,n="px",i=!1;if(this.cacheStateIfChanged(t,["visible"],o)&&(a.display=t.visible?"":"none"),this.cacheStateIfChanged(t,["alpha"],o)&&(a.opacity=t.alpha),t.visible&&!(t.alpha<=0)){if(this.cacheStateIfChanged(t,["width"],o)&&(a.width=t.width+n),this.cacheStateIfChanged(t,["height"],o)&&(a.height=t.height+n),this.cacheStateIfChanged(t,["depth"],o)&&(a.zIndex=t.depth+1),t.transform){var s=t.transform;(i=this.cacheStateIfChanged(t,["pivotX","pivotY"],o))&&(a[r+"TransformOrigin"]="0 0"),a[r+"Transform"]="matrix3d("+s.a+", "+s.b+", 0, 0, "+s.c+", "+s.d+", 0, 0, 0, 0, 1, 0, "+s.tx+", "+s.ty+", 0, 1)"}else(i=this.cacheStateIfChanged(t,["pivotX","pivotY"],o))&&(a[r+"TransformOrigin"]=t.pivotX+n+" "+t.pivotY+n),(this.cacheStateIfChanged(t,["x","y","rotation","scaleX","scaleY"],o)||i)&&(a[r+"Transform"]=this.getTransformCSS(t));this.cacheStateIfChanged(t,["background"],o)&&(a.backgroundColor=t.background),a.pointerEvents||(a.pointerEvents="none");var f=e.image;if(f){var h=f.src;h!==o.image&&(o.image=h,a.backgroundImage="url("+h+")");var d=e.rect;if(d){var l=d[0],g=d[1];l!==o.sx&&(o.sx=l,a.backgroundPositionX=-l+n),g!==o.sy&&(o.sy=g,a.backgroundPositionY=-g+n)}}var p=t.mask;if(p){var m=p.drawable.domElement.style.backgroundImage;m!==o.maskImage&&(o.maskImage=m,a[r+"MaskImage"]=m,a[r+"MaskRepeat"]="no-repeat");var T=p.x,u=p.y;T===o.maskX&&u===o.maskY||(o.maskX=T,o.maskY=u,a[r+"MaskPosition"]=T+n+" "+u+n)}}},cacheStateIfChanged:function(t,e,a){var o,r,n,i,s=!1;for(o=0,r=e.length;o -1){ - eventListeners.splice(index, 1); - } - } - } - - if(eventListeners.length == 0) delete listeners[eventType]; - return true; - } - return false; - } -}; - -/** - * @language=en - * Event Object class. It's an private class now, but maybe will become a public class if needed. - */ -var EventObject = Class.create({ - constructor: function EventObject(type, target, detail){ - this.type = type; - this.target = target; - this.detail = detail; - this.timeStamp = +new Date(); - }, - - type: null, - target: null, - detail: null, - timeStamp: 0, - - stopImmediatePropagation: function(){ - this._stopped = true; - } -}); - -//Trick: `stopImmediatePropagation` compatibility -var RawEvent = window.Event; -if(RawEvent){ - var proto = RawEvent.prototype, - stop = proto.stopImmediatePropagation; - proto.stopImmediatePropagation = function(){ - stop && stop.call(this); - this._stopped = true; - }; -} - -window.Hilo.EventMixin = EventMixin; -})(window); \ No newline at end of file +!function(t){t.Hilo||(t.Hilo={});var e=t.Hilo.Class,i={_listeners:null,on:function(t,e,i){for(var n=this._listeners=this._listeners||{},r=n[t]=n[t]||[],s=0,l=r.length;s-1&&l.splice(f,1)}}return 0==l.length&&delete s[r],!0}return!1}},n=e.create({constructor:function(t,e,i){this.type=t,this.target=e,this.detail=i,this.timeStamp=+new Date},type:null,target:null,detail:null,timeStamp:0,stopImmediatePropagation:function(){this._stopped=!0}}),r=t.Event;if(r){var s=r.prototype,l=s.stopImmediatePropagation;s.stopImmediatePropagation=function(){l&&l.call(this),this._stopped=!0}}t.Hilo.EventMixin=i}(window); \ No newline at end of file diff --git a/build/standalone/hilo/game/Camera.js b/build/standalone/hilo/game/Camera.js index 9fa9bcf1..a64ea290 100644 --- a/build/standalone/hilo/game/Camera.js +++ b/build/standalone/hilo/game/Camera.js @@ -1,5 +1,5 @@ /** - * Hilo 1.5.0 for standalone + * Hilo 1.6.0 for standalone * Copyright 2016 alibaba.com * Licensed under the MIT License */ diff --git a/build/standalone/hilo/game/Camera.min.js b/build/standalone/hilo/game/Camera.min.js index 87cdc7dc..77a282c3 100644 --- a/build/standalone/hilo/game/Camera.min.js +++ b/build/standalone/hilo/game/Camera.min.js @@ -1,98 +1,6 @@ /** - * Hilo 1.5.0 for standalone + * Hilo 1.6.0 for standalone * Copyright 2016 alibaba.com * Licensed under the MIT License */ -/** - * Hilo 1.5.0 for standalone - * Copyright 2016 alibaba.com - * Licensed under the MIT License - */ -(function(window){ -if(!window.Hilo) window.Hilo = {}; -var Class = window.Hilo.Class; -var util = window.Hilo.util; - - -/** - * @language=en - * @class Camera. - * @param {Object} properties The properties to create a view object, contains all writeable props of this class - * @module hilo/game/Camera - * @requires hilo/core/Class - * @requires hilo/util/util - * @property {Number} width The width of the camera. - * @property {Number} height The height of the camera. - * @property {Object} scroll The scrolling value of the camera {x:0, y:0}. - * @property {View} target The target that the camera follow. - * @property {Array} bounds The rect area where camera is allowed to move [x, y, width, height]. - * @property {Array} deadzone The rect area where camera isn't allowed to move[ x, y, width, height]. - */ -var Camera = Class.create(/** @lends Camera.prototype */{ - constructor:function(properties){ - this.width = 0; - this.height = 0; - - this.target = null; - this.deadzone = null; - this.bounds = null; - - this.scroll = { - x:0, - y:0 - }; - - util.copy(this, properties); - }, - /** - * @language=en - * update. - * @param {Number} deltaTime - */ - tick:function(deltaTime){ - var target = this.target; - var scroll = this.scroll; - var bounds = this.bounds; - var deadzone = this.deadzone; - - if(target){ - var viewX, viewY; - if(deadzone){ - viewX = Math.min(Math.max(target.x - scroll.x, deadzone[0]), deadzone[0] + deadzone[2]); - viewY = Math.min(Math.max(target.y - scroll.y, deadzone[1]), deadzone[1] + deadzone[3]); - } - else{ - viewX = this.width * .5; - viewY = this.height * .5; - } - - scroll.x = target.x - viewX; - scroll.y = target.y - viewY; - - if(bounds){ - scroll.x = Math.min(Math.max(scroll.x, bounds[0]), bounds[0] + bounds[2]); - scroll.y = Math.min(Math.max(scroll.y, bounds[1]), bounds[1] + bounds[3]); - } - } - else{ - scroll.x = 0; - scroll.y = 0; - } - }, - /** - * @language=en - * Follow the target. - * @param {Object} target The target that the camera follow. It must has x and y properties. - * @param {Array} deadzone The rect area where camera isn't allowed to move[ x, y, width, height]. - */ - follow:function(target, deadzone){ - this.target = target; - if(deadzone !== undefined){ - this.deadzone = deadzone; - } - this.tick(); - } -}); - -window.Hilo.Camera = Camera; -})(window); \ No newline at end of file +!function(t){t.Hilo||(t.Hilo={});var i=t.Hilo.Class,h=t.Hilo.util,a=i.create({constructor:function(t){this.width=0,this.height=0,this.target=null,this.deadzone=null,this.bounds=null,this.scroll={x:0,y:0},h.copy(this,t)},tick:function(t){var i=this.target,h=this.scroll,a=this.bounds,s=this.deadzone;if(i){var o,n;s?(o=Math.min(Math.max(i.x-h.x,s[0]),s[0]+s[2]),n=Math.min(Math.max(i.y-h.y,s[1]),s[1]+s[3])):(o=.5*this.width,n=.5*this.height),h.x=i.x-o,h.y=i.y-n,a&&(h.x=Math.min(Math.max(h.x,a[0]),a[0]+a[2]),h.y=Math.min(Math.max(h.y,a[1]),a[1]+a[3]))}else h.x=0,h.y=0},follow:function(t,i){this.target=t,void 0!==i&&(this.deadzone=i),this.tick()}});t.Hilo.Camera=a}(window); \ No newline at end of file diff --git a/build/standalone/hilo/game/Camera3d.js b/build/standalone/hilo/game/Camera3d.js index 71012236..bed55a12 100644 --- a/build/standalone/hilo/game/Camera3d.js +++ b/build/standalone/hilo/game/Camera3d.js @@ -1,5 +1,5 @@ /** - * Hilo 1.5.0 for standalone + * Hilo 1.6.0 for standalone * Copyright 2016 alibaba.com * Licensed under the MIT License */ diff --git a/build/standalone/hilo/game/Camera3d.min.js b/build/standalone/hilo/game/Camera3d.min.js index 846e8642..0bd0ea29 100644 --- a/build/standalone/hilo/game/Camera3d.min.js +++ b/build/standalone/hilo/game/Camera3d.min.js @@ -1,192 +1,6 @@ /** - * Hilo 1.5.0 for standalone + * Hilo 1.6.0 for standalone * Copyright 2016 alibaba.com * Licensed under the MIT License */ -/** - * Hilo 1.5.0 for standalone - * Copyright 2016 alibaba.com - * Licensed under the MIT License - */ -(function(window){ -if(!window.Hilo) window.Hilo = {}; -var Class = window.Hilo.Class; -var util = window.Hilo.util; - - -/** - * @language=en - * @class Camera3d is a pseudo-3d camera. - * @module hilo/game/Camera3d - * @requires hilo/core/Class - * @requires hilo/util/util - * @property {Number} fv The distance of the fov(The distance between eyes and the Z plane,it determines the scale ratio of the 3d object). - * @property {Number} fx The x position of the screen viewpoint(The distance between the screen viewpoint and the screen left top corner on the x axis). - * @property {Number} fy The y position of the screen viewpoint(The distance between the screen viewpoint and the screen left top corner on the y axis). - * @property {Object} stage The 3d object's container, it can be stage or container.It is required if you need to sort the 3d object by z axis. - * @property {Number} x The x position. - * @property {Number} y The y position. - * @property {Number} z The z position. - * @property {Number} rotationX The x rotation. - * @property {Number} rotationY The y rotation. - * @property {Number} rotationZ The z rotation. - */ -var Camera3d = (function(){ - - var degtorad = Math.PI / 180; - - //Rotate the axis. - function rotateX(x, y, z, ca, sa) {//rotate x - return { - x: x, - y: y * ca - z * sa, - z: y * sa + z * ca - }; - } - function rotateY(x, y, z, ca, sa) {//rotate y - return { - x: x * ca - z * sa, - y: y, - z: x * sa + z * ca - }; - } - function rotateZ(x, y, z, ca, sa) {//rotate z - return { - x: x * ca - y * sa, - y: x * sa + y * ca, - z: z - }; - } - - var Camera3d = Class.create(/** @lends Camera3d.prototype */{ - - constructor: function(properties){ - properties.x = properties.x || 0; - properties.y = properties.y || 0; - properties.z = properties.z || 0; - properties.rotationX = properties.rotationX || 0; - properties.rotationY = properties.rotationY || 0; - properties.rotationZ = properties.rotationZ || 0; - - util.copy(this, properties); - }, - - /** - * @language=en - * Translate the camera,used for Zoomin/out feature. - * @param {Number} x The x position. - * @param {Number} y The y position. - * @param {Number} z The z position. - */ - translate : function(x,y,z){ - this.tx = x; - this.ty = y; - this.tz = z; - }, - - /** - * @language=en - * Rotate by the x axis. - * @param {Number} angle The rotate degree. - */ - rotateX : function(angle){ - this.rotationX = angle; - }, - - /** - * @language=en - * Rotate by the y axis. - * @param {Number} angle The rotate degree. - */ - rotateY : function(angle){ - this.rotationY = angle; - }, - - /** - * @language=en - * Rotate by the z axis. - * @param {Number} angle The rotate degree. - */ - rotateZ : function(angle){ - this.rotationZ = angle; - }, - - /** - * @language=en - * Project the 3d point to 2d point. - * @param {object} vector3D The 3d position, it must have x, y and z properties. - * @param {View} view The view related to the 3d position.It'll be auto translated by the 3d position. - * @returns {Object} The 2d object include z and scale properties, e.g.:{x:x, y:y, z:z, scale} - */ - project : function(vector3D, view){ - - var rx = this.rotationX * degtorad, - ry = this.rotationY * degtorad, - rz = this.rotationZ * degtorad, - - cosX = Math.cos(rx), sinX = Math.sin(rx), - cosY = Math.cos(ry), sinY = Math.sin(ry), - cosZ = Math.cos(rz), sinZ = Math.sin(rz), - - // 旋转变换前的 仿射矩阵位移, - dx = vector3D.x - this.x, - dy = vector3D.y - this.y, - dz = vector3D.z - this.z; - - // 旋转矩阵变换 - var vector = rotateZ(dx, dy, dz, cosZ, sinZ); - vector = rotateY(vector.x, vector.y, vector.z, cosY, sinY); - vector = rotateX(vector.x, vector.y, vector.z, cosX, sinX); - - // 最后的仿射矩阵变换 - if(this.tx) vector.x -= this.tx; - if(this.ty) vector.y -= this.ty; - if(this.tz) vector.z -= this.tz; - - var perspective = this.fv / (this.fv + vector.z), - _x = vector.x * perspective, - _y = -vector.y * perspective; - - var result = { - x : _x + this.fx, - y : _y + this.fy, - z : -vector.z, - scale : perspective - }; - - if(view){ - view.x = result.x; - view.y = result.y; - view.z = result.z; - view.scaleX = result.scale; - view.scaleY = result.scale; - } - - return result; - }, - - /** - * @language=en - * Sort by z axis. - */ - sortZ : function(){ - this.stage.children.sort(function(view_a, view_b){ - return view_a.z > view_b.z; - }); - }, - - /** - * @language=en - * Used for the ticker. - */ - tick : function(){ - this.sortZ(); - } - - }); - - return Camera3d; - -})(); -window.Hilo.Camera3d = Camera3d; -})(window); \ No newline at end of file +!function(t){t.Hilo||(t.Hilo={});var i=t.Hilo.Class,o=t.Hilo.util,n=function(){function t(t,i,o,n,s){return{x:t,y:i*n-o*s,z:i*s+o*n}}function n(t,i,o,n,s){return{x:t*n-o*s,y:i,z:t*s+o*n}}function s(t,i,o,n,s){return{x:t*n-i*s,y:t*s+i*n,z:o}}var r=Math.PI/180,a=i.create({constructor:function(t){t.x=t.x||0,t.y=t.y||0,t.z=t.z||0,t.rotationX=t.rotationX||0,t.rotationY=t.rotationY||0,t.rotationZ=t.rotationZ||0,o.copy(this,t)},translate:function(t,i,o){this.tx=t,this.ty=i,this.tz=o},rotateX:function(t){this.rotationX=t},rotateY:function(t){this.rotationY=t},rotateZ:function(t){this.rotationZ=t},project:function(i,o){var a=this.rotationX*r,h=this.rotationY*r,c=this.rotationZ*r,u=Math.cos(a),e=Math.sin(a),z=Math.cos(h),y=Math.sin(h),f=Math.cos(c),x=Math.sin(c),l=i.x-this.x,M=i.y-this.y,Z=i.z-this.z,v=s(l,M,Z,f,x);v=n(v.x,v.y,v.z,z,y),v=t(v.x,v.y,v.z,u,e),this.tx&&(v.x-=this.tx),this.ty&&(v.y-=this.ty),this.tz&&(v.z-=this.tz);var X=this.fv/(this.fv+v.z),Y=v.x*X,H=-v.y*X,d={x:Y+this.fx,y:H+this.fy,z:-v.z,scale:X};return o&&(o.x=d.x,o.y=d.y,o.z=d.z,o.scaleX=d.scale,o.scaleY=d.scale),d},sortZ:function(){this.stage.children.sort(function(t,i){return t.z>i.z})},tick:function(){this.sortZ()}});return a}();t.Hilo.Camera3d=n}(window); \ No newline at end of file diff --git a/build/standalone/hilo/game/ParticleSystem.js b/build/standalone/hilo/game/ParticleSystem.js index fea3f41d..01db9bf7 100644 --- a/build/standalone/hilo/game/ParticleSystem.js +++ b/build/standalone/hilo/game/ParticleSystem.js @@ -1,5 +1,5 @@ /** - * Hilo 1.5.0 for standalone + * Hilo 1.6.0 for standalone * Copyright 2016 alibaba.com * Licensed under the MIT License */ diff --git a/build/standalone/hilo/game/ParticleSystem.min.js b/build/standalone/hilo/game/ParticleSystem.min.js index 1ad660d4..b7b54129 100644 --- a/build/standalone/hilo/game/ParticleSystem.min.js +++ b/build/standalone/hilo/game/ParticleSystem.min.js @@ -1,323 +1,6 @@ /** - * Hilo 1.5.0 for standalone + * Hilo 1.6.0 for standalone * Copyright 2016 alibaba.com * Licensed under the MIT License */ -/** - * Hilo 1.5.0 for standalone - * Copyright 2016 alibaba.com - * Licensed under the MIT License - */ -(function(window){ -if(!window.Hilo) window.Hilo = {}; -var Hilo = window.Hilo;var Class = window.Hilo.Class; -var View = window.Hilo.View; -var Container = window.Hilo.Container; -var Drawable = window.Hilo.Drawable; -var util = window.Hilo.util; - - -/** - * @language=en - * - *
- * @class ParticleSystem A particle system. - * @augments Container - * @module hilo/game/ParticleSystem - * @requires hilo/core/Hilo - * @requires hilo/core/Class - * @requires hilo/view/View - * @requires hilo/view/Container - * @requires hilo/view/Drawable - * @requires hilo/util/util - * @property {Number} [emitTime=0.2] Emit time interval(in second). - * @property {Number} [emitTimeVar=0] Emit time interval variances. - * @property {Number} [emitNum=10] Emit number. - * @property {Number} [emitNumVar=0] Emit number variances. - * @property {Number} [emitterX=0] The emitter x position. - * @property {Number} [emitterY=0] The emitter y position. - * @property {Number} [totalTime=Infinity] Total time. - * @property {Number} [gx=0] The gravity x value. - * @property {Number} [gy=0] The gravity y value. - * @param {Object} properties properties The properties to create a view object, contains all writeable props of this class - * @param {Object} properties.particle The config of particle. - * @param {Number} [properties.particle.x=0] The x position. - * @param {Number} [properties.particle.y=0] The y position - * @param {Number} [properties.particle.vx=0] The x velocity. - * @param {Number} [properties.particle.vy=0] The y velocity. - * @param {Number} [properties.particle.ax=0] The x acceleration. - * @param {Number} [properties.particle.ay=0] The y acceleration. - * @param {Number} [properties.particle.life=1] The time particle lives(in second). - * @param {Number} [properties.particle.alpha=1] The alpha. - * @param {Number} [properties.particle.alphaV=0] The alpha decline rate. - * @param {Number} [properties.particle.scale=1] The scale. - * @param {Number} [properties.particle.scaleV=0] The scale decline rate. -*/ -var ParticleSystem = (function(){ - //粒子属性 - var props = ['x', 'y', 'vx', 'vy', 'ax', 'ay', 'rotation', 'rotationV', 'scale', 'scaleV', 'alpha', 'alphaV', 'life']; - var PROPS = []; - for(var i = 0, l = props.length;i < l;i ++){ - var p = props[i]; - PROPS.push(p); - PROPS.push(p + "Var"); - } - - //粒子默认值 - var PROPS_DEFAULT = { - x: 0, - y: 0, - vx: 0, - vy: 0, - ax: 0, - ay: 0, - scale:1, - scaleV:0, - alpha:1, - alphaV:0, - rotation: 0, - rotationV: 0, - life: 1 - }; - - var diedParticles = []; - - var ParticleSystem = Class.create(/** @lends ParticleSystem.prototype */{ - Extends:Container, - constructor:function(properties){ - this.id = this.id || properties.id || Hilo.getUid("ParticleSystem"); - - this.emitterX = 0; - this.emitterY = 0; - - this.gx = 0; - this.gy = 0; - this.totalTime = Infinity; - - this.emitNum = 10; - this.emitNumVar = 0; - - this.emitTime = .2; - this.emitTimeVar = 0; - - this.particle = {}; - - ParticleSystem.superclass.constructor.call(this, properties); - - this.reset(properties); - }, - Statics:{ - PROPS:PROPS, - PROPS_DEFAULT:PROPS_DEFAULT, - diedParticles:diedParticles - }, - /** - * @language=en - * Reset the properties. - * @param {Object} cfg - */ - reset: function(cfg) { - util.copy(this, cfg); - this.particle.system = this; - if(this.totalTime <= 0){ - this.totalTime = Infinity; - } - }, - /** - * @language=en - * 更新 - * @param {Number} dt delta time(in milliseconds) - */ - onUpdate: function(dt) { - dt *= .001; - if (this._isRun) { - this._totalRunTime += dt; - this._currentRunTime += dt; - if (this._currentRunTime >= this._emitTime) { - this._currentRunTime = 0; - this._emitTime = getRandomValue(this.emitTime, this.emitTimeVar); - this._emit(); - } - - if (this._totalRunTime >= this.totalTime) { - this.stop(); - } - } - }, - /** - * @language=en - * Emit particles. - */ - _emit: function() { - var num = getRandomValue(this.emitNum, this.emitNumVar)>>0; - for (var i = 0; i < num; i++) { - this.addChild(Particle.create(this.particle)); - } - }, - /** - * @language=en - * Start emit particles. - */ - start: function() { - this.stop(true); - this._currentRunTime = 0; - this._totalRunTime = 0; - this._isRun = true; - this._emitTime = getRandomValue(this.emitTime, this.emitTimeVar); - }, - /** - * @language=en - * Stop emit particles. - * @param {Boolean} clear Whether or not clear all the particles. - */ - stop: function(clear) { - this._isRun = false; - if (clear) { - for (var i = this.children.length - 1; i >= 0; i--) { - this.children[i].destroy(); - } - } - } - }); - - /** - * @language=en - * @class 粒子 - * @inner - * @param {Number} vx The x velocity. - * @param {Number} vy The y velocity. - * @param {Number} ax The x acceleration. - * @param {Number} ay The y acceleration. - * @param {Number} scaleV The scale decline rate. - * @param {Number} alphaV The alpha decline rate. - * @param {Number} rotationV The rotate speed. - * @param {Number} life The time particle lives(in seconds) - */ - var Particle = Class.create({ - Extends:View, - constructor:function(properties){ - this.id = this.id || properties.id || Hilo.getUid("Particle"); - Particle.superclass.constructor.call(this, properties); - this.init(properties); - }, - /** - * @language=en - * Update the particle. - */ - onUpdate: function(dt) { - dt *= .001; - if(this._died){ - return false; - } - var ax = this.ax + this.system.gx; - var ay = this.ay + this.system.gy; - - this.vx += ax * dt; - this.vy += ay * dt; - this.x += this.vx * dt; - this.y += this.vy * dt; - - this.rotation += this.rotationV; - - if (this._time > .1) { - this.alpha += this.alphaV; - } - - this.scale += this.scaleV; - this.scaleX = this.scaleY = this.scale; - - this._time += dt; - if (this._time >= this.life || this.alpha <= 0) { - this.destroy(); - return false; - } - }, - /** - * @language=en - * Set the image of particle. - */ - setImage: function(img, frame) { - this.drawable = this.drawable||new Drawable(); - frame = frame || [0, 0, img.width, img.height]; - - this.width = frame[2]; - this.height = frame[3]; - this.drawable.rect = frame; - this.drawable.image = img; - }, - /** - * @language=en - * Destroy the particle. - */ - destroy: function() { - this._died = true; - this.alpha = 0; - this.removeFromParent(); - diedParticles.push(this); - }, - /** - * @language=en - * Init the particle. - */ - init: function(cfg) { - this.system = cfg.system; - this._died = false; - this._time = 0; - this.alpha = 1; - for (var i = 0, l = PROPS.length; i < l; i++) { - var p = PROPS[i]; - var v = cfg[p] === undefined ? PROPS_DEFAULT[p] : cfg[p]; - this[p] = getRandomValue(v, cfg[p + 'Var']); - } - - this.x += this.system.emitterX; - this.y += this.system.emitterY; - - if (cfg.image) { - var frame = cfg.frame; - if(frame && frame[0].length){ - frame = frame[(Math.random() * frame.length) >> 0]; - } - this.setImage(cfg.image, frame); - if(cfg.pivotX !== undefined){ - this.pivotX = cfg.pivotX * frame[2]; - } - if(cfg.pivotY !== undefined){ - this.pivotY = cfg.pivotY * frame[3]; - } - } - }, - Statics:{ - /** - * @language=en - * Create the particle. - * @param {Object} cfg The config of particle. - */ - create:function(cfg) { - if (diedParticles.length > 0) { - var particle = diedParticles.pop(); - particle.init(cfg); - return particle; - } else { - return new Particle(cfg); - } - } - } - - }); - - /** - * Get the random value. - * @private - * @param {Number} value The value. - * @param {Number} variances The variances. - * @return {Number} - */ - function getRandomValue(value, variances){ - return variances ? value + (Math.random() - .5) * 2 * variances : value; - } - - return ParticleSystem; -})(); -window.Hilo.ParticleSystem = ParticleSystem; -})(window); \ No newline at end of file +!function(t){t.Hilo||(t.Hilo={});var i=t.Hilo,s=t.Hilo.Class,e=t.Hilo.View,h=t.Hilo.Container,a=t.Hilo.Drawable,r=t.Hilo.util,n=function(){function t(t,i){return i?t+2*(Math.random()-.5)*i:t}for(var n=["x","y","vx","vy","ax","ay","rotation","rotationV","scale","scaleV","alpha","alphaV","life"],o=[],l=0,m=n.length;l=this._emitTime&&(this._currentRunTime=0,this._emitTime=t(this.emitTime,this.emitTimeVar),this._emit()),this._totalRunTime>=this.totalTime&&this.stop())},_emit:function(){for(var i=t(this.emitNum,this.emitNumVar)>>0,s=0;s=0;i--)this.children[i].destroy()}}),v=s.create({Extends:e,constructor:function(t){this.id=this.id||t.id||i.getUid("Particle"),v.superclass.constructor.call(this,t),this.init(t)},onUpdate:function(t){if(t*=.001,this._died)return!1;var i=this.ax+this.system.gx,s=this.ay+this.system.gy;return this.vx+=i*t,this.vy+=s*t,this.x+=this.vx*t,this.y+=this.vy*t,this.rotation+=this.rotationV,this._time>.1&&(this.alpha+=this.alphaV),this.scale+=this.scaleV,this.scaleX=this.scaleY=this.scale,this._time+=t,this._time>=this.life||this.alpha<=0?(this.destroy(),!1):void 0},setImage:function(t,i){this.drawable=this.drawable||new a,i=i||[0,0,t.width,t.height],this.width=i[2],this.height=i[3],this.drawable.rect=i,this.drawable.image=t},destroy:function(){this._died=!0,this.alpha=0,this.removeFromParent(),d.push(this)},init:function(i){this.system=i.system,this._died=!1,this._time=0,this.alpha=1;for(var s=0,e=o.length;s>0]),this.setImage(i.image,r),void 0!==i.pivotX&&(this.pivotX=i.pivotX*r[2]),void 0!==i.pivotY&&(this.pivotY=i.pivotY*r[3])}},Statics:{create:function(t){if(d.length>0){var i=d.pop();return i.init(t),i}return new v(t)}}});return p}();t.Hilo.ParticleSystem=n}(window); \ No newline at end of file diff --git a/build/standalone/hilo/geom/Matrix.js b/build/standalone/hilo/geom/Matrix.js index 655e755e..66963607 100644 --- a/build/standalone/hilo/geom/Matrix.js +++ b/build/standalone/hilo/geom/Matrix.js @@ -1,5 +1,5 @@ /** - * Hilo 1.5.0 for standalone + * Hilo 1.6.0 for standalone * Copyright 2016 alibaba.com * Licensed under the MIT License */ diff --git a/build/standalone/hilo/geom/Matrix.min.js b/build/standalone/hilo/geom/Matrix.min.js index afd61d57..16777353 100644 --- a/build/standalone/hilo/geom/Matrix.min.js +++ b/build/standalone/hilo/geom/Matrix.min.js @@ -1,228 +1,6 @@ /** - * Hilo 1.5.0 for standalone + * Hilo 1.6.0 for standalone * Copyright 2016 alibaba.com * Licensed under the MIT License */ -/** - * Hilo 1.5.0 for standalone - * Copyright 2016 alibaba.com - * Licensed under the MIT License - */ -(function(window){ -if(!window.Hilo) window.Hilo = {}; -var Class = window.Hilo.Class; - - -/** - * @language=en - * @class Matrix class is a transforming matrix, which declare how points in one coordinate maped to another coordinate. - * @param {Number} a The value affects pixel positioning alongside the x axis when Scale or rotate images. - * @param {Number} b The value affects pixel positioning alongside the y axis when rotate or skew images. - * @param {Number} c The value affects pixel positioning alongside the x axis when rotate or skew images. - * @param {Number} d The value affects pixel positioning alongside the y axis when Scale or rotate images. - * @param {Number} tx The distance to move every point alongside the x axis. - * @param {Number} ty The distance to move every point alongside the y axis. - * @module hilo/geom/Matrix - * @requires hilo/core/Class - */ -var Matrix = Class.create(/** @lends Matrix.prototype */{ - constructor: function(a, b, c, d, tx, ty){ - this.a = a; - this.b = b; - this.c = c; - this.d = d; - this.tx = tx; - this.ty = ty; - }, - - /** - * set - * @param {Number} a - * @param {Number} b - * @param {Number} c - * @param {Number} d - * @param {Number} tx - * @param {Number} ty - */ - set: function(a, b, c, d, tx, ty){ - this.a = a; - this.b = b; - this.c = c; - this.d = d; - this.tx = tx; - this.ty = ty; - - return this; - }, - - /** - * copy - * @param {Matrix} mat - * @return {Matrix} this - */ - copy: function(mat){ - this.a = mat.a; - this.b = mat.b; - this.c = mat.c; - this.d = mat.d; - this.tx = mat.tx; - this.ty = mat.ty; - - return this; - }, - - /** - * clone - * @return {Matrix} - */ - clone: function(){ - return new Matrix().copy(this); - }, - - /** - * @language=en - * Link a Matrix to current Matrix, in order to make geometry effects on these two composed more effective. - * @param {Matrix} mtx Matrix that link to the source matrix. - * @returns {Matrix} A Matrix Object. - */ - concat: function(mtx){ - var args = arguments, - a = this.a, b = this.b, c = this.c, d = this.d, - tx = this.tx, ty = this.ty; - - var ma, mb, mc, md, mx, my; - if(args.length >= 6){ - ma = args[0]; - mb = args[1]; - mc = args[2]; - md = args[3]; - mx = args[4]; - my = args[5]; - } - else{ - ma = mtx.a; - mb = mtx.b; - mc = mtx.c; - md = mtx.d; - mx = mtx.tx; - my = mtx.ty; - } - - this.a = a * ma + b * mc; - this.b = a * mb + b * md; - this.c = c * ma + d * mc; - this.d = c * mb + d * md; - this.tx = tx * ma + ty * mc + mx; - this.ty = tx * mb + ty * md + my; - return this; - }, - - /** - * @language=en - * Rotate the Matrix Object. - * @param {Number} angle The angle to rotate. - * @returns {Matrix} A Matrix object. - */ - rotate: function(angle){ - var sin = Math.sin(angle), cos = Math.cos(angle), - a = this.a, b = this.b, c = this.c, d = this.d, - tx = this.tx, ty = this.ty; - - this.a = a * cos - b * sin; - this.b = a * sin + b * cos; - this.c = c * cos - d * sin; - this.d = c * sin + d * cos; - this.tx = tx * cos - ty * sin; - this.ty = tx * sin + ty * cos; - return this; - }, - - /** - * @language=en - * Scale the Matrix. - * @param {Number} sx The value to multiply those object scale alongside the x axis. - * @param {Number} sy The value to multiply those object scale alongside the y axis. - * @returns {Matrix} A Matrix object. - */ - scale: function(sx, sy){ - this.a *= sx; - this.d *= sy; - this.c *= sx; - this.b *= sy; - this.tx *= sx; - this.ty *= sy; - return this; - }, - - /** - * @language=en - * Translate the Matrix alongside x axis and y axis by dx and dy. - * @param {Number} dx Translate Matrix alongside the x axis to the right (measured in px). - * @param {Number} dy Translate Matrix alongside the y axis to the right (measured in px). - * @returns {Matrix} A Matrix object. - */ - translate: function(dx, dy){ - this.tx += dx; - this.ty += dy; - return this; - }, - - /** - * @language=en - * Set each Matrix property a value to trigger null transform. The Matrix after applying identity matrix transformation will be exactly the same as original. - * @returns {Matrix} A Matrix object. - */ - identity: function(){ - this.a = this.d = 1; - this.b = this.c = this.tx = this.ty = 0; - return this; - }, - - /** - * @language=en - * Apply an invert transformation of original Matrix. Using this invert transformation, you can reset a Matrix to a state before it had been apply some Matrix. - * @returns {Matrix} A Matrix object. - */ - invert: function(){ - var a = this.a; - var b = this.b; - var c = this.c; - var d = this.d; - var tx = this.tx; - var i = a * d - b * c; - - this.a = d / i; - this.b = -b / i; - this.c = -c / i; - this.d = a / i; - this.tx = (c * this.ty - d * tx) / i; - this.ty = -(a * this.ty - b * tx) / i; - return this; - }, - - /** - * @language=en - * Return the result after apply a Matrix displaying transform on the point. - * @param {Object} point Point need to transform. - * @param {Boolean} round Whether ceil the coordinate values of the point. - * @param {Boolean} returnNew Whether return a new point. - * @returns {Object} 由应用矩阵转换所产生的点。 - */ - transformPoint: function(point, round, returnNew){ - var x = point.x * this.a + point.y * this.c + this.tx, - y = point.x * this.b + point.y * this.d + this.ty; - - if(round){ - x = x + 0.5 >> 0; - y = y + 0.5 >> 0; - } - if(returnNew) return {x:x, y:y}; - point.x = x; - point.y = y; - return point; - } - -}); - -window.Hilo.Matrix = Matrix; -})(window); \ No newline at end of file +!function(t){t.Hilo||(t.Hilo={});var i=t.Hilo.Class,s=i.create({constructor:function(t,i,s,h,n,c){this.a=t,this.b=i,this.c=s,this.d=h,this.tx=n,this.ty=c},set:function(t,i,s,h,n,c){return this.a=t,this.b=i,this.c=s,this.d=h,this.tx=n,this.ty=c,this},copy:function(t){return this.a=t.a,this.b=t.b,this.c=t.c,this.d=t.d,this.tx=t.tx,this.ty=t.ty,this},clone:function(){return(new s).copy(this)},concat:function(t){var i,s,h,n,c,r,a=arguments,o=this.a,u=this.b,y=this.c,e=this.d,x=this.tx,d=this.ty;return a.length>=6?(i=a[0],s=a[1],h=a[2],n=a[3],c=a[4],r=a[5]):(i=t.a,s=t.b,h=t.c,n=t.d,c=t.tx,r=t.ty),this.a=o*i+u*h,this.b=o*s+u*n,this.c=y*i+e*h,this.d=y*s+e*n,this.tx=x*i+d*h+c,this.ty=x*s+d*n+r,this},rotate:function(t){var i=Math.sin(t),s=Math.cos(t),h=this.a,n=this.b,c=this.c,r=this.d,a=this.tx,o=this.ty;return this.a=h*s-n*i,this.b=h*i+n*s,this.c=c*s-r*i,this.d=c*i+r*s,this.tx=a*s-o*i,this.ty=a*i+o*s,this},scale:function(t,i){return this.a*=t,this.d*=i,this.c*=t,this.b*=i,this.tx*=t,this.ty*=i,this},translate:function(t,i){return this.tx+=t,this.ty+=i,this},identity:function(){return this.a=this.d=1,this.b=this.c=this.tx=this.ty=0,this},invert:function(){var t=this.a,i=this.b,s=this.c,h=this.d,n=this.tx,c=t*h-i*s;return this.a=h/c,this.b=-i/c,this.c=-s/c,this.d=t/c,this.tx=(s*this.ty-h*n)/c,this.ty=-(t*this.ty-i*n)/c,this},transformPoint:function(t,i,s){var h=t.x*this.a+t.y*this.c+this.tx,n=t.x*this.b+t.y*this.d+this.ty;return i&&(h=h+.5>>0,n=n+.5>>0),s?{x:h,y:n}:(t.x=h,t.y=n,t)}});t.Hilo.Matrix=s}(window); \ No newline at end of file diff --git a/build/standalone/hilo/loader/ImageLoader.js b/build/standalone/hilo/loader/ImageLoader.js index bafab2c7..2bd5a9a2 100644 --- a/build/standalone/hilo/loader/ImageLoader.js +++ b/build/standalone/hilo/loader/ImageLoader.js @@ -1,5 +1,5 @@ /** - * Hilo 1.5.0 for standalone + * Hilo 1.6.0 for standalone * Copyright 2016 alibaba.com * Licensed under the MIT License */ diff --git a/build/standalone/hilo/loader/ImageLoader.min.js b/build/standalone/hilo/loader/ImageLoader.min.js index 963a0f00..d873d51d 100644 --- a/build/standalone/hilo/loader/ImageLoader.min.js +++ b/build/standalone/hilo/loader/ImageLoader.min.js @@ -1,52 +1,6 @@ /** - * Hilo 1.5.0 for standalone + * Hilo 1.6.0 for standalone * Copyright 2016 alibaba.com * Licensed under the MIT License */ -/** - * Hilo 1.5.0 for standalone - * Copyright 2016 alibaba.com - * Licensed under the MIT License - */ -(function(window){ -if(!window.Hilo) window.Hilo = {}; -var Class = window.Hilo.Class; - - -/** - * @language=en - * @private - * @class image resources loader. - * @module hilo/loader/ImageLoader - * @requires hilo/core/Class - */ -var ImageLoader = Class.create({ - load: function(data){ - var me = this; - - var image = new Image(); - if(data.crossOrigin){ - image.crossOrigin = "Anonymous"; - } - - image.onload = function(){ - me.onLoad(image); - }; - image.onerror = image.onabort = me.onError.bind(image); - image.src = data.src + (data.noCache ? (data.src.indexOf('?') == -1 ? '?' : '&') + 't=' + (+new Date()) : ''); - }, - - onLoad: function(image){ - image.onload = image.onerror = image.onabort = null; - return image; - }, - - onError: function(e){ - var image = e.target; - image.onload = image.onerror = image.onabort = null; - return e; - } - -}); -window.Hilo.ImageLoader = ImageLoader; -})(window); \ No newline at end of file +!function(o){o.Hilo||(o.Hilo={});var n=o.Hilo.Class,r=n.create({load:function(o){var n=this,r=new Image;o.crossOrigin&&(r.crossOrigin="Anonymous"),r.onload=function(){n.onLoad(r)},r.onerror=r.onabort=n.onError.bind(r),r.src=o.src+(o.noCache?(o.src.indexOf("?")==-1?"?":"&")+"t="+ +new Date:"")},onLoad:function(o){return o.onload=o.onerror=o.onabort=null,o},onError:function(o){var n=o.target;return n.onload=n.onerror=n.onabort=null,o}});o.Hilo.ImageLoader=r}(window); \ No newline at end of file diff --git a/build/standalone/hilo/loader/LoadQueue.js b/build/standalone/hilo/loader/LoadQueue.js index 563ae87a..2757dd60 100644 --- a/build/standalone/hilo/loader/LoadQueue.js +++ b/build/standalone/hilo/loader/LoadQueue.js @@ -1,5 +1,5 @@ /** - * Hilo 1.5.0 for standalone + * Hilo 1.6.0 for standalone * Copyright 2016 alibaba.com * Licensed under the MIT License */ @@ -95,6 +95,23 @@ var LoadQueue = Class.create(/** @lends LoadQueue.prototype */{ var item = this.get(id); return item && item.content; }, + /** + * @language=en + * remove resource object content by id or src + * @param {String} specified id or src + */ + removeContent: function(id){ + if(id){ + var source = this._source; + for(var i = 0; i < source.length; i++){ + var item = source[i]; + if(item.id === id || item.src === id){ + source.splice(i, 1); + return; + } + } + } + }, /** * @language=en diff --git a/build/standalone/hilo/loader/LoadQueue.min.js b/build/standalone/hilo/loader/LoadQueue.min.js index 2805595e..2424541e 100644 --- a/build/standalone/hilo/loader/LoadQueue.min.js +++ b/build/standalone/hilo/loader/LoadQueue.min.js @@ -1,257 +1,6 @@ /** - * Hilo 1.5.0 for standalone + * Hilo 1.6.0 for standalone * Copyright 2016 alibaba.com * Licensed under the MIT License */ -/** - * Hilo 1.5.0 for standalone - * Copyright 2016 alibaba.com - * Licensed under the MIT License - */ -(function(window){ -if(!window.Hilo) window.Hilo = {}; -var Class = window.Hilo.Class; -var EventMixin = window.Hilo.EventMixin; -var ImageLoader = window.Hilo.ImageLoader; -var ScriptLoader = window.Hilo.ScriptLoader; - - -//TODO: 超时timeout,失败重连次数maxTries,更多的下载器Loader,队列暂停恢复等。 - -/** - * @language=en - * @class LoadQueue is a queue-like loader. - * @mixes EventMixin - * @borrows EventMixin#on as #on - * @borrows EventMixin#off as #off - * @borrows EventMixin#fire as #fire - * @param {Object} source resource that need to be loaded,could be a single object or array resource. - * @module hilo/loader/LoadQueue - * @requires hilo/core/Class - * @requires hilo/event/EventMixin - * @requires hilo/loader/ImageLoader - * @requires hilo/loader/ScriptLoader - * @property {Int} maxConnections the limited concurrent connections. default value 2. - */ -var LoadQueue = Class.create(/** @lends LoadQueue.prototype */{ - Mixes: EventMixin, - constructor: function(source){ - this._source = []; - this.add(source); - }, - - maxConnections: 2, //TODO: 应该是每个host的最大连接数。 - - _source: null, - _loaded: 0, - _connections: 0, - _currentIndex: -1, - - /** - * @language=en - * Add desired resource,could be a single object or array resource. - * @param {Object|Array} source ,a single object or array resource. Each resource contains properties like below: - *
    - *
  • id - resource identifier
  • - *
  • src - resource url
  • - *
  • type - resource type. By default, we automatically identify resource by file suffix and choose the relevant loader for you
  • - *
  • loader - specified resource loader. If you specify this,we abandon choosing loader inside
  • - *
  • noCache - a tag that set on or off to prevent cache,implemented by adding timestamp inside
  • - *
  • size - predicted resource size, help calculating loading progress
  • - *
  • crossOrigin - Whether cross-domain is needed, default is false
  • - *
- * @returns {LoadQueue} 下载队列实例本身。 - */ - add: function(source){ - var me = this; - if(source){ - source = source instanceof Array ? source : [source]; - me._source = me._source.concat(source); - } - return me; - }, - - /** - * @language=en - * get resource object by id or src - * @param {String} specified id or src - * @returns {Object} resource object - */ - get: function(id){ - if(id){ - var source = this._source; - for(var i = 0; i < source.length; i++){ - var item = source[i]; - if(item.id === id || item.src === id){ - return item; - } - } - } - return null; - }, - - /** - * @language=en - * get resource object content by id or src - * @param {String} specified id or src - * @returns {Object} resource object content - */ - getContent: function(id){ - var item = this.get(id); - return item && item.content; - }, - - /** - * @language=en - * start loading - * @returns {LoadQueue} the loading instance - */ - start: function(){ - var me = this; - me._loadNext(); - return me; - }, - - /** - * @language=en - * @private - */ - _loadNext: function(){ - var me = this, source = me._source, len = source.length; - - //all items loaded - if(me._loaded >= len){ - me.fire('complete'); - return; - } - - if(me._currentIndex < len - 1 && me._connections < me.maxConnections){ - var index = ++me._currentIndex; - var item = source[index]; - var loader = me._getLoader(item); - - if(loader){ - var onLoad = loader.onLoad, onError = loader.onError; - - loader.onLoad = function(e){ - loader.onLoad = onLoad; - loader.onError = onError; - var content = onLoad && onLoad.call(loader, e) || e.target; - me._onItemLoad(index, content); - }; - loader.onError = function(e){ - loader.onLoad = onLoad; - loader.onError = onError; - onError && onError.call(loader, e); - me._onItemError(index, e); - }; - me._connections++; - } - - me._loadNext(); - loader && loader.load(item); - } - }, - - /** - * @language=en - * @private - */ - _getLoader: function(item){ - var loader = item.loader; - if(loader) return loader; - - var type = item.type || getExtension(item.src); - - switch(type){ - case 'png': - case 'jpg': - case 'jpeg': - case 'gif': - case 'webp': - loader = new ImageLoader(); - break; - case 'js': - case 'jsonp': - loader = new ScriptLoader(); - break; - } - - return loader; - }, - - /** - * @language=en - * @private - */ - _onItemLoad: function(index, content){ - var me = this, item = me._source[index]; - item.loaded = true; - item.content = content; - me._connections--; - me._loaded++; - me.fire('load', item); - me._loadNext(); - }, - - /** - * @language=en - * @private - */ - _onItemError: function(index, e){ - var me = this, item = me._source[index]; - item.error = e; - me._connections--; - me._loaded++; - me.fire('error', item); - me._loadNext(); - }, - - /** - * @language=en - * get resource size, loaded or all. - * @param {Boolean} identify loaded or all resource. default is false, return all resource size. when set true, return loaded resource size. - * @returns {Number} resource size. - */ - getSize: function(loaded){ - var size = 0, source = this._source; - for(var i = 0; i < source.length; i++){ - var item = source[i]; - size += (loaded ? item.loaded && item.size : item.size) || 0; - } - return size; - }, - - /** - * @language=en - * get loaded resource count - * @returns {Uint} loaded resource count - */ - getLoaded: function(){ - return this._loaded; - }, - - /** - * @language=en - * get all resource count - * @returns {Uint} all resource count - */ - getTotal: function(){ - return this._source.length; - } - -}); - -/** - * @language=en - * @private - */ -function getExtension(src){ - var extRegExp = /\/?[^/]+\.(\w+)(\?\S+)?$/i, match, extension; - if(match = src.match(extRegExp)){ - extension = match[1].toLowerCase(); - } - return extension || null; -} -window.Hilo.LoadQueue = LoadQueue; -})(window); \ No newline at end of file +!function(o){function e(o){var e,n,r=/\/?[^\/]+\.(\w+)(\?\S+)?$/i;return(e=o.match(r))&&(n=e[1].toLowerCase()),n||null}o.Hilo||(o.Hilo={});var n=o.Hilo.Class,r=o.Hilo.EventMixin,t=o.Hilo.ImageLoader,i=o.Hilo.ScriptLoader,a=n.create({Mixes:r,constructor:function(o){this._source=[],this.add(o)},maxConnections:2,_source:null,_loaded:0,_connections:0,_currentIndex:-1,add:function(o){var e=this;return o&&(o=o instanceof Array?o:[o],e._source=e._source.concat(o)),e},get:function(o){if(o)for(var e=this._source,n=0;n=n)return void o.fire("complete");if(o._currentIndex start/stop - if(!audioNode.start){ - audioNode.start = audioNode.noteOn; - audioNode.stop = audioNode.noteOff; - } - - audioNode.buffer = this._buffer; - audioNode.onended = this._onAudioEvent; - this._gainNode.gain.value = this.muted ? 0 : this.volume; - audioNode.connect(this._gainNode); - audioNode.start(0, this._offset); - - this._audioNode = audioNode; - this._startTime = this._context.currentTime; - this.playing = true; - }, - - /** - * @private - */ - _clearAudioNode: function(){ - var audioNode = this._audioNode; - if(audioNode){ - audioNode.onended = null; - // audioNode.disconnect(this._gainNode); - audioNode.disconnect(0); - this._audioNode = null; - } - }, - - /** - * @language=en - * Play the audio. Restart playing the audio from the beginning if already playing. - */ - play: function(){ - if(this.playing) this.stop(); - - if(this.loaded){ - this._doPlay(); - }else if(!this._buffer){ - this.autoPlay = true; - this.load(); - } - - return this; - }, - - /** - * @language=en - * Pause (halt) playing the audio. - */ - pause: function(){ - if(this.playing){ - this._audioNode.stop(0); - this._offset += this._context.currentTime - this._startTime; - this.playing = false; - } - return this; - }, - - /** - * @language=en - * Continue to play the audio. - */ - resume: function(){ - if(!this.playing){ - this._doPlay(); - } - return this; - }, - - /** - * @language=en - * Stop playing the audio. - */ - stop: function(){ - if(this.playing){ - this._audioNode.stop(0); - this._audioNode.disconnect(); - this._offset = 0; - this.playing = false; - } - return this; - }, - - /** - * @language=en - * Set the volume. - */ - setVolume: function(volume){ - if(this.volume != volume){ - this.volume = volume; - this._gainNode.gain.value = volume; - } - return this; - }, - - /** - * @language=en - * Set mute mode. - */ - setMute: function(muted){ - if(this.muted != muted){ - this.muted = muted; - this._gainNode.gain.value = muted ? 0 : this.volume; - } - return this; - }, - - Statics: /** @lends WebAudio */ { - /** - * @language=en - * Does the browser support WebAudio. - */ - isSupported: context !== null, - - /** - * @language=en - * Does browser activate WebAudio already. - */ - enabled: false, - - /** - * @language=en - * Activate WebAudio. Note: Require user action events to activate. Once activated, can play audio without user action events. - */ - enable: function(){ - if(!this.enabled && context){ - var source = context.createBufferSource(); - source.buffer = context.createBuffer(1, 1, 22050); - source.connect(context.destination); - source.start ? source.start(0, 0, 0) : source.noteOn(0, 0, 0); - this.enabled = true; - return true; - } - return this.enabled; - }, - /** - * The audio buffer caches. - * @private - * @type {Object} - */ - _bufferCache:{}, - /** - * @language=en - * Clear the audio buffer cache. - * @param {String} url audio's url. if url is none, it will clear all buffer. - */ - clearBufferCache:function(url){ - if(url){ - this._bufferCache[url] = null; - } - else{ - this._bufferCache = {}; - } - } - } -}); - -})(); -window.Hilo.WebAudio = WebAudio; -})(window); \ No newline at end of file +!function(t){t.Hilo||(t.Hilo={});var e=t.Hilo.Class,i=t.Hilo.util,o=t.Hilo.EventMixin,n=function(){var s=null;try{var r=t.AudioContext||t.webkitAudioContext;r&&(s=new r)}catch(a){s=null}return e.create({Mixes:o,constructor:function(t){i.copy(this,t,!0),this._init()},src:null,loop:!1,autoPlay:!1,loaded:!1,playing:!1,duration:0,volume:1,muted:!1,_context:null,_gainNode:null,_buffer:null,_audioNode:null,_startTime:0,_offset:0,_init:function(){this._context=s,this._gainNode=s.createGain?s.createGain():s.createGainNode(),this._gainNode.connect(s.destination),this._onAudioEvent=this._onAudioEvent.bind(this),this._onDecodeComplete=this._onDecodeComplete.bind(this),this._onDecodeError=this._onDecodeError.bind(this)},load:function(){if(!this._buffer){var t=n._bufferCache[this.src];if(t)this._onDecodeComplete(t);else{var e=new XMLHttpRequest;e.src=this.src,e.open("GET",this.src,!0),e.responseType="arraybuffer",e.onload=this._onAudioEvent,e.onprogress=this._onAudioEvent,e.onerror=this._onAudioEvent,e.send()}this._buffer=!0}return this},_onAudioEvent:function(t){var e=t.type;switch(e){case"load":var i=t.target;i.onload=i.onprogress=i.onerror=null,this._context.decodeAudioData(i.response,this._onDecodeComplete,this._onDecodeError),i=null;break;case"ended":this.playing=!1,this.fire("end"),this.loop&&this._doPlay();break;case"progress":this.fire(t);break;case"error":this.fire(t)}},_onDecodeComplete:function(t){n._bufferCache[this.src]||(n._bufferCache[this.src]=t),this._buffer=t,this.loaded=!0,this.duration=t.duration,this.fire("load"),this.autoPlay&&this._doPlay()},_onDecodeError:function(){this.fire("error")},_doPlay:function(){this._clearAudioNode();var t=this._context.createBufferSource();t.start||(t.start=t.noteOn,t.stop=t.noteOff),t.buffer=this._buffer,t.onended=this._onAudioEvent,this._gainNode.gain.value=this.muted?0:this.volume,t.connect(this._gainNode),t.start(0,this._offset),this._audioNode=t,this._startTime=this._context.currentTime,this.playing=!0},_clearAudioNode:function(){var t=this._audioNode;t&&(t.onended=null,t.disconnect(0),this._audioNode=null)},play:function(){return this.playing&&this.stop(),this.loaded?this._doPlay():this._buffer||(this.autoPlay=!0,this.load()),this},pause:function(){return this.playing&&(this._audioNode.stop(0),this._offset+=this._context.currentTime-this._startTime,this.playing=!1),this},resume:function(){return this.playing||this._doPlay(),this},stop:function(){return this.playing&&(this._audioNode.stop(0),this._audioNode.disconnect(),this._offset=0,this.playing=!1),this},setVolume:function(t){return this.volume!=t&&(this.volume=t,this._gainNode.gain.value=t),this},setMute:function(t){return this.muted!=t&&(this.muted=t,this._gainNode.gain.value=t?0:this.volume),this},Statics:{isSupported:null!==s,enabled:!1,enable:function(){if(!this.enabled&&s){var t=s.createBufferSource();return t.buffer=s.createBuffer(1,1,22050),t.connect(s.destination),t.start?t.start(0,0,0):t.noteOn(0,0,0),this.enabled=!0,!0}return this.enabled},_bufferCache:{},clearBufferCache:function(t){t?this._bufferCache[t]=null:this._bufferCache={}}}})}();t.Hilo.WebAudio=n}(window); \ No newline at end of file diff --git a/build/standalone/hilo/media/WebSound.js b/build/standalone/hilo/media/WebSound.js index 94c7d144..f9910583 100644 --- a/build/standalone/hilo/media/WebSound.js +++ b/build/standalone/hilo/media/WebSound.js @@ -1,5 +1,5 @@ /** - * Hilo 1.5.0 for standalone + * Hilo 1.6.0 for standalone * Copyright 2016 alibaba.com * Licensed under the MIT License */ diff --git a/build/standalone/hilo/media/WebSound.min.js b/build/standalone/hilo/media/WebSound.min.js index 47a3f854..5cc73b1e 100644 --- a/build/standalone/hilo/media/WebSound.min.js +++ b/build/standalone/hilo/media/WebSound.min.js @@ -1,109 +1,6 @@ /** - * Hilo 1.5.0 for standalone + * Hilo 1.6.0 for standalone * Copyright 2016 alibaba.com * Licensed under the MIT License */ -/** - * Hilo 1.5.0 for standalone - * Copyright 2016 alibaba.com - * Licensed under the MIT License - */ -(function(window){ -if(!window.Hilo) window.Hilo = {}; -var HTMLAudio = window.Hilo.HTMLAudio; -var WebAudio = window.Hilo.WebAudio; -var util = window.Hilo.util; - - -/** - * @language=en - * - *
- * demo: - *
- * var audio = WebSound.getAudio({
- *     src: 'test.mp3',
- *     loop: false,
- *     volume: 1
- * }).on('load', function(e){
- *     console.log('load');
- * }).on('end', function(e){
- *     console.log('end');
- * }).play();
- * 
- * @class Audio playing manager. - * @static - * @module hilo/media/WebSound - * @requires hilo/media/HTMLAudio - * @requires hilo/media/WebAudio - * @requires hilo/util/util - */ -var WebSound = { - _audios: {}, - - /** - * @language=en - * Activate audio function. Note: Require user action events to activate. Currently support WebAudio. - */ - enableAudio: function(){ - if(WebAudio.isSupported){ - WebAudio.enable(); - } - }, - - /** - * @language=en - * Get audio element. Default use WebAudio if supported. - * @param {String|Object} source If String, it's the source of the audio; If Object, it should contains a src property. - * @param {Boolean} [preferWebAudio=true] Whether or not to use WebAudio first, default is true. - * @returns {WebAudio|HTMLAudio} Audio playing instance. - */ - getAudio: function(source, preferWebAudio){ - if(preferWebAudio === undefined){ - preferWebAudio = true; - } - - source = this._normalizeSource(source); - var audio = this._audios[source.src]; - if(!audio){ - if(preferWebAudio && WebAudio.isSupported){ - audio = new WebAudio(source); - }else if(HTMLAudio.isSupported){ - audio = new HTMLAudio(source); - } - this._audios[source.src] = audio; - } - - return audio; - }, - - /** - * @language=en - * Remove audio element. - * @param {String|Object} source If String, it's the source of the audio; If Object, it should contains a src property. - */ - removeAudio: function(source){ - var src = typeof source === 'string' ? source : source.src; - var audio = this._audios[src]; - if(audio){ - audio.stop(); - audio.off(); - this._audios[src] = null; - delete this._audios[src]; - } - }, - - /** - * @language=en - * @private - */ - _normalizeSource: function(source){ - var result = {}; - if(typeof source === 'string') result = {src:source}; - else util.copy(result, source); - return result; - } - -}; -window.Hilo.WebSound = WebSound; -})(window); \ No newline at end of file +!function(i){i.Hilo||(i.Hilo={});var o=i.Hilo.HTMLAudio,u=i.Hilo.WebAudio,e=i.Hilo.util,t={_audios:{},enableAudio:function(){u.isSupported&&u.enable()},getAudio:function(i,e){void 0===e&&(e=!0),i=this._normalizeSource(i);var t=this._audios[i.src];return t||(e&&u.isSupported?t=new u(i):o.isSupported&&(t=new o(i)),this._audios[i.src]=t),t},removeAudio:function(i){var o="string"==typeof i?i:i.src,u=this._audios[o];u&&(u.stop(),u.off(),this._audios[o]=null,delete this._audios[o])},_normalizeSource:function(i){var o={};return"string"==typeof i?o={src:i}:e.copy(o,i),o}};i.Hilo.WebSound=t}(window); \ No newline at end of file diff --git a/build/standalone/hilo/renderer/CanvasRenderer.js b/build/standalone/hilo/renderer/CanvasRenderer.js index ba317989..89caff87 100644 --- a/build/standalone/hilo/renderer/CanvasRenderer.js +++ b/build/standalone/hilo/renderer/CanvasRenderer.js @@ -1,5 +1,5 @@ /** - * Hilo 1.5.0 for standalone + * Hilo 1.6.0 for standalone * Copyright 2016 alibaba.com * Licensed under the MIT License */ diff --git a/build/standalone/hilo/renderer/CanvasRenderer.min.js b/build/standalone/hilo/renderer/CanvasRenderer.min.js index a3f7bd3b..5ad644b7 100644 --- a/build/standalone/hilo/renderer/CanvasRenderer.min.js +++ b/build/standalone/hilo/renderer/CanvasRenderer.min.js @@ -1,216 +1,6 @@ /** - * Hilo 1.5.0 for standalone + * Hilo 1.6.0 for standalone * Copyright 2016 alibaba.com * Licensed under the MIT License */ -/** - * Hilo 1.5.0 for standalone - * Copyright 2016 alibaba.com - * Licensed under the MIT License - */ -(function(window){ -if(!window.Hilo) window.Hilo = {}; -var Class = window.Hilo.Class; -var Hilo = window.Hilo;var Renderer = window.Hilo.Renderer; - - -/** - * @language=en - * @class CanvasRenderer CanvasRenderer, all the visual object is drawing on the canvas element.The stage will create different renderer depend on the canvas and renderType properties, developer need not use this class directly. - * @augments Renderer - * @param {Object} properties The properties to create a renderer, contains all writeable props of this class. - * @module hilo/renderer/CanvasRenderer - * @requires hilo/core/Class - * @requires hilo/core/Hilo - * @requires hilo/renderer/Renderer - * @property {CanvasRenderingContext2D} context The context of the canvas element, readonly. - */ -var CanvasRenderer = Class.create( /** @lends CanvasRenderer.prototype */ { - Extends: Renderer, - constructor: function(properties) { - CanvasRenderer.superclass.constructor.call(this, properties); - - this.context = this.canvas.getContext("2d"); - }, - renderType: 'canvas', - context: null, - - /** - * @private - * @see Renderer#startDraw - */ - startDraw: function(target) { - if (target.visible && target.alpha > 0) { - if (target === this.stage) { - this.context.clearRect(0, 0, target.width, target.height); - } - if (target.blendMode !== this.blendMode) { - this.context.globalCompositeOperation = this.blendMode = target.blendMode; - } - this.context.save(); - return true; - } - return false; - }, - - /** - * @private - * @see Renderer#draw - */ - draw: function(target) { - var ctx = this.context, - w = target.width, - h = target.height; - - //draw background - var bg = target.background; - if (bg) { - ctx.fillStyle = bg; - ctx.fillRect(0, 0, w, h); - } - - //draw image - var drawable = target.drawable, - image = drawable && drawable.image; - if (image) { - var rect = drawable.rect, - sw = rect[2], - sh = rect[3], - offsetX = rect[4], - offsetY = rect[5]; - //ie9+浏览器宽高为0时会报错 fixed ie9 bug. - if (!sw || !sh) { - return; - } - if (!w && !h) { - //fix width/height TODO: how to get rid of this? - w = target.width = sw; - h = target.height = sh; - } - //the pivot is the center of frame if has offset, otherwise is (0, 0) - if (offsetX || offsetY) ctx.translate(offsetX - sw * 0.5, offsetY - sh * 0.5); - ctx.drawImage(image, rect[0], rect[1], sw, sh, 0, 0, w, h); - } - }, - - /** - * @private - * @see Renderer#endDraw - */ - endDraw: function(target) { - this.context.restore(); - }, - - /** - * @private - * @see Renderer#transform - */ - transform: function(target) { - var drawable = target.drawable; - if (drawable && drawable.domElement) { - Hilo.setElementStyleByView(target); - return; - } - - var ctx = this.context, - scaleX = target.scaleX, - scaleY = target.scaleY; - - if (target === this.stage) { - var style = this.canvas.style, - oldScaleX = target._scaleX, - oldScaleY = target._scaleY, - isStyleChange = false; - - if ((!oldScaleX && scaleX != 1) || (oldScaleX && oldScaleX != scaleX)) { - target._scaleX = scaleX; - style.width = scaleX * target.width + "px"; - isStyleChange = true; - } - if ((!oldScaleY && scaleY != 1) || (oldScaleY && oldScaleY != scaleY)) { - target._scaleY = scaleY; - style.height = scaleY * target.height + "px"; - isStyleChange = true; - } - if (isStyleChange) { - target.updateViewport(); - } - } else { - var x = target.x, - y = target.y, - pivotX = target.pivotX, - pivotY = target.pivotY, - rotation = target.rotation % 360, - transform = target.transform, - mask = target.mask; - - if (mask) { - mask._render(this); - ctx.clip(); - } - - //alignment - var align = target.align; - if (align) { - var pos = target.getAlignPosition(); - x = pos.x; - y = pos.y; - } - - if (transform) { - ctx.transform(transform.a, transform.b, transform.c, transform.d, transform.tx, transform.ty); - } else { - if (x != 0 || y != 0) ctx.translate(x, y); - if (rotation != 0) ctx.rotate(rotation * Math.PI / 180); - if (scaleX != 1 || scaleY != 1) ctx.scale(scaleX, scaleY); - if (pivotX != 0 || pivotY != 0) ctx.translate(-pivotX, -pivotY); - } - - } - - if (target.alpha > 0) ctx.globalAlpha *= target.alpha; - }, - - /** - * @private - * @see Renderer#remove - */ - remove: function(target) { - var drawable = target.drawable; - var elem = drawable && drawable.domElement; - - if (elem) { - var parentElem = elem.parentNode; - if (parentElem) { - parentElem.removeChild(elem); - } - } - }, - - /** - * @private - * @see Renderer#clear - */ - clear: function(x, y, width, height) { - this.context.clearRect(x, y, width, height); - }, - - /** - * @private - * @see Renderer#resize - */ - resize: function(width, height) { - var canvas = this.canvas; - var stage = this.stage; - var style = canvas.style; - - canvas.width = width; - canvas.height = height; - - style.width = stage.width * stage.scaleX + 'px'; - style.height = stage.height * stage.scaleY + 'px'; - } - -}); -window.Hilo.CanvasRenderer = CanvasRenderer; -})(window); \ No newline at end of file +!function(t){t.Hilo||(t.Hilo={});var e=t.Hilo.Class,a=t.Hilo,i=t.Hilo.Renderer,n=e.create({Extends:i,constructor:function(t){n.superclass.constructor.call(this,t),this.context=this.canvas.getContext("2d")},renderType:"canvas",context:null,startDraw:function(t){return!!(t.visible&&t.alpha>0)&&(t===this.stage&&this.context.clearRect(0,0,t.width,t.height),t.blendMode!==this.blendMode&&(this.context.globalCompositeOperation=this.blendMode=t.blendMode),this.context.save(),!0)},draw:function(t){var e=this.context,a=t.width,i=t.height,n=t.background;n&&(e.fillStyle=n,e.fillRect(0,0,a,i));var r=t.drawable,s=r&&r.image;if(s){var l=r.rect,o=l[2],c=l[3],h=l[4],d=l[5];if(!o||!c)return;a||i||(a=t.width=o,i=t.height=c),(h||d)&&e.translate(h-.5*o,d-.5*c),e.drawImage(s,l[0],l[1],o,c,0,0,a,i)}},endDraw:function(t){this.context.restore()},transform:function(t){var e=t.drawable;if(e&&e.domElement)return void a.setElementStyleByView(t);var i=this.context,n=t.scaleX,r=t.scaleY;if(t===this.stage){var s=this.canvas.style,l=t._scaleX,o=t._scaleY,c=!1;(!l&&1!=n||l&&l!=n)&&(t._scaleX=n,s.width=n*t.width+"px",c=!0),(!o&&1!=r||o&&o!=r)&&(t._scaleY=r,s.height=r*t.height+"px",c=!0),c&&t.updateViewport()}else{var h=t.x,d=t.y,v=t.pivotX,f=t.pivotY,g=t.rotation%360,w=t.transform,p=t.mask;p&&(p._render(this),i.clip());var u=t.align;if(u){var x=t.getAlignPosition();h=x.x,d=x.y}w?i.transform(w.a,w.b,w.c,w.d,w.tx,w.ty):(0==h&&0==d||i.translate(h,d),0!=g&&i.rotate(g*Math.PI/180),1==n&&1==r||i.scale(n,r),0==v&&0==f||i.translate(-v,-f))}t.alpha>0&&(i.globalAlpha*=t.alpha)},remove:function(t){var e=t.drawable,a=e&&e.domElement;if(a){var i=a.parentNode;i&&i.removeChild(a)}},clear:function(t,e,a,i){this.context.clearRect(t,e,a,i)},resize:function(t,e){var a=this.canvas,i=this.stage,n=a.style;a.width=t,a.height=e,n.width=i.width*i.scaleX+"px",n.height=i.height*i.scaleY+"px"}});t.Hilo.CanvasRenderer=n}(window); \ No newline at end of file diff --git a/build/standalone/hilo/renderer/DOMRenderer.js b/build/standalone/hilo/renderer/DOMRenderer.js index ec74a7ae..58601a83 100644 --- a/build/standalone/hilo/renderer/DOMRenderer.js +++ b/build/standalone/hilo/renderer/DOMRenderer.js @@ -1,5 +1,5 @@ /** - * Hilo 1.5.0 for standalone + * Hilo 1.6.0 for standalone * Copyright 2016 alibaba.com * Licensed under the MIT License */ diff --git a/build/standalone/hilo/renderer/DOMRenderer.min.js b/build/standalone/hilo/renderer/DOMRenderer.min.js index ba035570..e75058da 100644 --- a/build/standalone/hilo/renderer/DOMRenderer.min.js +++ b/build/standalone/hilo/renderer/DOMRenderer.min.js @@ -1,188 +1,6 @@ /** - * Hilo 1.5.0 for standalone + * Hilo 1.6.0 for standalone * Copyright 2016 alibaba.com * Licensed under the MIT License */ -/** - * Hilo 1.5.0 for standalone - * Copyright 2016 alibaba.com - * Licensed under the MIT License - */ -(function(window){ -if(!window.Hilo) window.Hilo = {}; -var Class = window.Hilo.Class; -var Hilo = window.Hilo;var Renderer = window.Hilo.Renderer; -var Drawable = window.Hilo.Drawable; - - -/** - * @language=en - * @class DomRenderer The DomRenderer, all the visual object is drawing using dom element.The stage will create different renderer depend on the canvas and renderType properties, developer need not use this class directly. - * @augments Renderer - * @param {Object} properties The properties to create a renderer, contains all writeable props of this class. - * @module hilo/renderer/DOMRenderer - * @requires hilo/core/Class - * @requires hilo/core/Hilo - * @requires hilo/renderer/Renderer - * @requires hilo/view/Drawable - */ -var DOMRenderer = (function(){ - -return Class.create({ - Extends: Renderer, - constructor: function(properties){ - DOMRenderer.superclass.constructor.call(this, properties); - }, - renderType:'dom', - /** - * @private - * @see Renderer#startDraw - */ - startDraw: function(target){ - //prepare drawable - var drawable = (target.drawable = target.drawable || new Drawable()); - drawable.domElement = drawable.domElement || createDOMDrawable(target, drawable); - return true; - }, - - /** - * @private - * @see Renderer#draw - */ - draw: function(target){ - var parent = target.parent, - targetElem = target.drawable.domElement, - currentParent = targetElem.parentNode; - - if(parent){ - var parentElem = parent.drawable.domElement; - if(parentElem != currentParent){ - parentElem.appendChild(targetElem); - } - //fix image load bug - if(!target.width && !target.height){ - var rect = target.drawable.rect; - if(rect && (rect[2] || rect[3])){ - target.width = rect[2]; - target.height = rect[3]; - } - } - } - else if(target === this.stage && !currentParent){ - targetElem.style.overflow = 'hidden'; - this.canvas.appendChild(targetElem); - } - }, - - /** - * @private - * @see Renderer#transform - */ - transform: function(target){ - Hilo.setElementStyleByView(target); - if(target === this.stage){ - var style = this.canvas.style, - oldScaleX = target._scaleX, - oldScaleY = target._scaleY, - scaleX = target.scaleX, - scaleY = target.scaleY; - - if((!oldScaleX && scaleX != 1) || (oldScaleX && oldScaleX != scaleX)){ - target._scaleX = scaleX; - style.width = scaleX * target.width + "px"; - } - if((!oldScaleY && scaleY != 1) || (oldScaleY && oldScaleY != scaleY)){ - target._scaleY = scaleY; - style.height = scaleY * target.height + "px"; - } - } - }, - - /** - * @private - * @see Renderer#remove - */ - remove: function(target){ - var drawable = target.drawable; - var elem = drawable && drawable.domElement; - - if(elem){ - var parentElem = elem.parentNode; - if(parentElem){ - parentElem.removeChild(elem); - } - } - }, - - /** - * @private - * @see Renderer#hide - */ - hide: function(target){ - var elem = target.drawable && target.drawable.domElement; - if(elem) elem.style.display = 'none'; - }, - - /** - * @private - * @see Renderer#resize - */ - resize: function(width, height){ - var style = this.canvas.style; - style.width = width + 'px'; - style.height = height + 'px'; - if(style.position != "absolute") { - style.position = "relative"; - } - } -}); - -/** - * @language=en - * Create a dom element, you can set the tagName property,such as canvas and div. - * @param {Object} view A visual object. - * @param {Object} imageObj The image object to render, include the image propertiy and other associated properties, such as rect. - * @return {HTMLElement} The created dom element. - * @private - */ -function createDOMDrawable(view, imageObj){ - var tag = view.tagName || "div", - img = imageObj.image, - w = view.width || (img && img.width), - h = view.height || (img && img.height), - elem = Hilo.createElement(tag), style = elem.style; - - if(view.id) elem.id = view.id; - style.position = "absolute"; - style.left = (view.left || 0) + "px"; - style.top = (view.top || 0) + "px"; - style.width = w + "px"; - style.height = h + "px"; - - if(tag == "canvas"){ - elem.width = w; - elem.height = h; - if(img){ - var ctx = elem.getContext("2d"); - var rect = imageObj.rect || [0, 0, w, h]; - ctx.drawImage(img, rect[0], rect[1], rect[2], rect[3], - (view.x || 0), (view.y || 0), - (view.width || rect[2]), - (view.height || rect[3])); - } - }else{ - style.opacity = view.alpha != undefined ? view.alpha : 1; - if(view === this.stage || view.clipChildren) style.overflow = "hidden"; - if(img && img.src){ - style.backgroundImage = "url(" + img.src + ")"; - var bgX = view.rectX || 0, bgY = view.rectY || 0; - style.backgroundPosition = (-bgX) + "px " + (-bgY) + "px"; - } - } - return elem; -} - -})(); - -window.Hilo.DOMRenderer = DOMRenderer; -})(window); \ No newline at end of file +!function(e){e.Hilo||(e.Hilo={});var t=e.Hilo.Class,a=e.Hilo,i=e.Hilo.Renderer,r=e.Hilo.Drawable,n=function(){function e(e,t){var i=e.tagName||"div",r=t.image,n=e.width||r&&r.width,l=e.height||r&&r.height,o=a.createElement(i),d=o.style;if(e.id&&(o.id=e.id),d.position="absolute",d.left=(e.left||0)+"px",d.top=(e.top||0)+"px",d.width=n+"px",d.height=l+"px","canvas"==i){if(o.width=n,o.height=l,r){var s=o.getContext("2d"),h=t.rect||[0,0,n,l];s.drawImage(r,h[0],h[1],h[2],h[3],e.x||0,e.y||0,e.width||h[2],e.height||h[3])}}else if(d.opacity=void 0!=e.alpha?e.alpha:1,(e===this.stage||e.clipChildren)&&(d.overflow="hidden"),r&&r.src){d.backgroundImage="url("+r.src+")";var c=e.rectX||0,p=e.rectY||0;d.backgroundPosition=-c+"px "+-p+"px"}return o}return t.create({Extends:i,constructor:function(e){n.superclass.constructor.call(this,e)},renderType:"dom",startDraw:function(t){var a=t.drawable=t.drawable||new r;return a.domElement=a.domElement||e(t,a),!0},draw:function(e){var t=e.parent,a=e.drawable.domElement,i=a.parentNode;if(t){var r=t.drawable.domElement;if(r!=i&&r.appendChild(a),!e.width&&!e.height){var n=e.drawable.rect;n&&(n[2]||n[3])&&(e.width=n[2],e.height=n[3])}}else e!==this.stage||i||(a.style.overflow="hidden",this.canvas.appendChild(a))},transform:function(e){if(a.setElementStyleByView(e),e===this.stage){var t=this.canvas.style,i=e._scaleX,r=e._scaleY,n=e.scaleX,l=e.scaleY;(!i&&1!=n||i&&i!=n)&&(e._scaleX=n,t.width=n*e.width+"px"),(!r&&1!=l||r&&r!=l)&&(e._scaleY=l,t.height=l*e.height+"px")}},remove:function(e){var t=e.drawable,a=t&&t.domElement;if(a){var i=a.parentNode;i&&i.removeChild(a)}},hide:function(e){var t=e.drawable&&e.drawable.domElement;t&&(t.style.display="none")},resize:function(e,t){var a=this.canvas.style;a.width=e+"px",a.height=t+"px","absolute"!=a.position&&(a.position="relative")}})}();e.Hilo.DOMRenderer=n}(window); \ No newline at end of file diff --git a/build/standalone/hilo/renderer/Renderer.js b/build/standalone/hilo/renderer/Renderer.js index 661c3298..6c05350f 100644 --- a/build/standalone/hilo/renderer/Renderer.js +++ b/build/standalone/hilo/renderer/Renderer.js @@ -1,5 +1,5 @@ /** - * Hilo 1.5.0 for standalone + * Hilo 1.6.0 for standalone * Copyright 2016 alibaba.com * Licensed under the MIT License */ diff --git a/build/standalone/hilo/renderer/Renderer.min.js b/build/standalone/hilo/renderer/Renderer.min.js index 6063e1f9..a2ef15bf 100644 --- a/build/standalone/hilo/renderer/Renderer.min.js +++ b/build/standalone/hilo/renderer/Renderer.min.js @@ -1,99 +1,6 @@ /** - * Hilo 1.5.0 for standalone + * Hilo 1.6.0 for standalone * Copyright 2016 alibaba.com * Licensed under the MIT License */ -/** - * Hilo 1.5.0 for standalone - * Copyright 2016 alibaba.com - * Licensed under the MIT License - */ -(function(window){ -if(!window.Hilo) window.Hilo = {}; -var Class = window.Hilo.Class; -var util = window.Hilo.util; - - -/** - * @language=en - * @class Renderer Renderer is the base class of renderer. - * @param {Object} properties The properties to create a renderer, contains all writeable props of this class. - * @module hilo/renderer/Renderer - * @requires hilo/core/Class - * @requires hilo/util/util - * @property {Object} canvas The canvas of renderer. It can be a dom element, such as a div element, or a canvas element. readonly. - * @property {Object} stage The stage of renderer, readonly. - * @property {String} renderType The render type of renderer, readonly. - */ -var Renderer = Class.create(/** @lends Renderer.prototype */{ - constructor: function(properties){ - properties = properties || {}; - util.copy(this, properties, true); - }, - - renderType:null, - canvas: null, - stage: null, - blendMode:'source-over', - - /** - * @language=en - * Prepare for draw visual object. The subclass need to implement it. - * @param {View} target The visual target to draw. - */ - startDraw: function(target){ }, - - /** - * @language=en - * Draw the visual object. The subclass need to implement it. - * @param {View} target The visual target to draw. - */ - draw: function(target){ }, - - /** - * @language=en - * The handling method after draw the visual object. The subclass need to implement it. - * @param {View} target The visual target to draw. - */ - endDraw: function(target){ }, - - /** - * @language=en - * Transfrom the visual object. The subclass need to implement it. - */ - transform: function(){ }, - - /** - * @language=en - * Hide the visual object. The subclass need to implement it. - */ - hide: function(){ }, - - /** - * @language=en - * Remove the visual object from canvas. Notice that it dosen't remove the object from stage. The subclass need to implement it. - * @param {View} target The visual target to remove. - */ - remove: function(target){ }, - - /** - * @language=en - * Clear the given region of canvas. The subclass need to implement it. - * @param {Number} x The position on the x axis of the given region. - * @param {Number} y The position on the y axis of the given region. - * @param {Number} width The width of the given region. - * @param {Number} height The height of the given region. - */ - clear: function(x, y, width, height){ }, - - /** - * @language=en - * Resize the renderer's canvas. - * @param {Number} width The width of renderer's canvas. - * @param {Number} height The height of the renderer's canvas. - */ - resize: function(width, height){ } - -}); -window.Hilo.Renderer = Renderer; -})(window); \ No newline at end of file +!function(n){n.Hilo||(n.Hilo={});var o=n.Hilo.Class,e=n.Hilo.util,i=o.create({constructor:function(n){n=n||{},e.copy(this,n,!0)},renderType:null,canvas:null,stage:null,blendMode:"source-over",startDraw:function(n){},draw:function(n){},endDraw:function(n){},transform:function(){},hide:function(){},remove:function(n){},clear:function(n,o,e,i){},resize:function(n,o){}});n.Hilo.Renderer=i}(window); \ No newline at end of file diff --git a/build/standalone/hilo/renderer/WebGLRenderer.js b/build/standalone/hilo/renderer/WebGLRenderer.js index 851676b6..71738aa7 100644 --- a/build/standalone/hilo/renderer/WebGLRenderer.js +++ b/build/standalone/hilo/renderer/WebGLRenderer.js @@ -1,5 +1,5 @@ /** - * Hilo 1.5.0 for standalone + * Hilo 1.6.0 for standalone * Copyright 2016 alibaba.com * Licensed under the MIT License */ diff --git a/build/standalone/hilo/renderer/WebGLRenderer.min.js b/build/standalone/hilo/renderer/WebGLRenderer.min.js index e7588e58..f815a403 100644 --- a/build/standalone/hilo/renderer/WebGLRenderer.min.js +++ b/build/standalone/hilo/renderer/WebGLRenderer.min.js @@ -1,590 +1,6 @@ /** - * Hilo 1.5.0 for standalone + * Hilo 1.6.0 for standalone * Copyright 2016 alibaba.com * Licensed under the MIT License */ -/** - * Hilo 1.5.0 for standalone - * Copyright 2016 alibaba.com - * Licensed under the MIT License - */ -(function(window){ -if(!window.Hilo) window.Hilo = {}; -var Class = window.Hilo.Class; -var Hilo = window.Hilo;var Renderer = window.Hilo.Renderer; -var Matrix = window.Hilo.Matrix; - - -/** - * Heavily inspired by PIXI's SpriteRenderer: - * https://github.com/pixijs/pixi.js/blob/v3.0.9/src/core/sprites/webgl/SpriteRenderer.js - */ - -var DEG2RAD = Math.PI / 180; -/** - * @language=en - * @class WebGLRenderer The WebGLRenderer, all the visual object is drawing on the canvas using WebGL.The stage will create different renderer depend on the canvas and renderType properties, developer need not use this class directly. - * @augments Renderer - * @param {Object} properties The properties to create a renderer, contains all writeable props of this class. - * @module hilo/renderer/WebGLRenderer - * @requires hilo/core/Class - * @requires hilo/core/Hilo - * @requires hilo/renderer/Renderer - * @requires hilo/geom/Matrix - * @property {WebGLRenderingContext} gl The WebGL context of the renderer, readonly. - */ -var WebGLRenderer = Class.create(/** @lends WebGLRenderer.prototype */{ - Extends: Renderer, - Statics:/** @lends WebGLRenderer */{ - /** - * @language=en - * The max num of batch draw, default is 2000. - * @type {Number} - */ - MAX_BATCH_NUM:2000, - /** - * @language=en - * The num of vertex attributes, readonly. - * @type {Number} - */ - ATTRIBUTE_NUM:5, - /** - * @language=en - * is WebGL supported, readonly. - * @type {Boolean} - */ - isSupport:function(){ - if(this._isSupported == undefined){ - var canvas = document.createElement('canvas'); - if(canvas.getContext && (canvas.getContext('webgl')||canvas.getContext('experimental-webgl'))){ - this._isSupported = true; - } - else{ - this._isSupported = false; - } - } - return this._isSupported; - }, - /** - * WebGL context Options - * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/getContextAttributes - * @type {Object} - */ - contextOptions: null - }, - renderType:'webgl', - gl:null, - _isContextLost:false, - _cacheTexture:{}, - constructor: function(properties){ - WebGLRenderer.superclass.constructor.call(this, properties); - var that = this; - var contextOptions = WebGLRenderer.contextOptions || {}; - this.gl = this.canvas.getContext("webgl", contextOptions)||this.canvas.getContext('experimental-webgl', contextOptions); - - this.maxBatchNum = WebGLRenderer.MAX_BATCH_NUM; - this.positionStride = WebGLRenderer.ATTRIBUTE_NUM * 4; - var vertexNum = this.maxBatchNum * WebGLRenderer.ATTRIBUTE_NUM * 4; - var indexNum = this.maxBatchNum * 6; - this.arrayBuffer = new ArrayBuffer(vertexNum * 4); - this.float32Array = new Float32Array(this.arrayBuffer); - this.uint32Array = new Uint32Array(this.arrayBuffer); - this.indexs = new Uint16Array(indexNum); - for (var i=0, j=0; i < indexNum; i += 6, j += 4) - { - this.indexs[i + 0] = j + 0; - this.indexs[i + 1] = j + 1; - this.indexs[i + 2] = j + 2; - this.indexs[i + 3] = j + 1; - this.indexs[i + 4] = j + 2; - this.indexs[i + 5] = j + 3; - } - this.batchIndex = 0; - this.sprites = []; - - this.canvas.addEventListener('webglcontextlost', function(e){ - that._isContextLost = true; - e.preventDefault(); - }, false); - - this.canvas.addEventListener('webglcontextrestored', function(e){ - that._isContextLost = false; - that.setupWebGLStateAndResource(); - }, false); - - this.setupWebGLStateAndResource(); - }, - setupWebGLStateAndResource:function(){ - var gl = this.gl; - gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA); - gl.clearColor(0, 0, 0, 0); - gl.disable(gl.DEPTH_TEST); - gl.disable(gl.CULL_FACE); - gl.enable(gl.BLEND); - - this._cacheTexture = {}; - this._initShaders(); - this.defaultShader.active(); - - this.positionBuffer = gl.createBuffer(); - this.indexBuffer = gl.createBuffer(); - - gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.indexBuffer); - gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, this.indexs, gl.STATIC_DRAW); - - gl.bindBuffer(gl.ARRAY_BUFFER, this.positionBuffer); - gl.bufferData(gl.ARRAY_BUFFER, this.arrayBuffer, gl.DYNAMIC_DRAW); - - gl.vertexAttribPointer(this.a_position, 2, gl.FLOAT, false, this.positionStride, 0);//x, y - gl.vertexAttribPointer(this.a_TexCoord, 2, gl.FLOAT, false, this.positionStride, 2 * 4);//x, y - gl.vertexAttribPointer(this.a_tint, 4, gl.UNSIGNED_BYTE, true, this.positionStride, 4 * 4);//alpha - }, - - context: null, - - /** - * @private - * @see Renderer#startDraw - */ - startDraw: function(target){ - if(target.visible && target.alpha > 0){ - if(target === this.stage){ - this.clear(); - } - return true; - } - return false; - }, - /** - * @private - * @see Renderer#draw - */ - draw: function(target){ - var w = target.width, - h = target.height; - - //TODO:draw background - var bg = target.background; // jshint ignore:line - - //draw image - var drawable = target.drawable, image = drawable && drawable.image; - if(image){ - var rect = drawable.rect, sw = rect[2], sh = rect[3]; - if(!w && !h){ - //fix width/height TODO: how to get rid of this? - w = target.width = sw; - h = target.height = sh; - } - - if(this.batchIndex >= this.maxBatchNum){ - this._renderBatches(); - } - - var vertexs = this._createVertexs(image, rect[0], rect[1], sw, sh, 0, 0, w, h); - var index = this.batchIndex * this.positionStride; - var float32Array = this.float32Array; - var uint32Array = this.uint32Array; - - var tint = (target.tint >> 16) + (target.tint & 0xff00) + ((target.tint & 0xff) << 16) + (target.__webglRenderAlpha * 255 << 24); - - float32Array[index + 0] = vertexs[0];//x - float32Array[index + 1] = vertexs[1];//y - float32Array[index + 2] = vertexs[2];//uvx - float32Array[index + 3] = vertexs[3];//uvy - uint32Array[index + 4] = tint;//tint - - float32Array[index + 5] = vertexs[4]; - float32Array[index + 6] = vertexs[5]; - float32Array[index + 7] = vertexs[6]; - float32Array[index + 8] = vertexs[7]; - uint32Array[index + 9] = tint; - - float32Array[index + 10] = vertexs[8]; - float32Array[index + 11] = vertexs[9]; - float32Array[index + 12] = vertexs[10]; - float32Array[index + 13] = vertexs[11]; - uint32Array[index + 14] = tint; - - float32Array[index + 15] = vertexs[12]; - float32Array[index + 16] = vertexs[13]; - float32Array[index + 17] = vertexs[14]; - float32Array[index + 18] = vertexs[15]; - uint32Array[index + 19] = tint; - - var matrix = target.__webglWorldMatrix; - for(var i = 0;i < 4;i ++){ - var x = float32Array[index + i*5]; - var y = float32Array[index + i*5 + 1]; - - float32Array[index + i*5] = matrix.a*x + matrix.c*y + matrix.tx; - float32Array[index + i*5 + 1] = matrix.b*x + matrix.d*y + matrix.ty; - } - - target.__textureImage = image; - this.sprites[this.batchIndex++] = target; - } - }, - - /** - * @private - * @see Renderer#endDraw - */ - endDraw: function(target){ - if(target === this.stage){ - this._renderBatches(); - } - }, - /** - * @private - * @see Renderer#transform - */ - transform: function(target){ - var drawable = target.drawable; - if(drawable && drawable.domElement){ - Hilo.setElementStyleByView(target); - return; - } - - var scaleX = target.scaleX, - scaleY = target.scaleY; - - if(target === this.stage){ - var style = this.canvas.style, - oldScaleX = target._scaleX, - oldScaleY = target._scaleY, - isStyleChange = false; - - if((!oldScaleX && scaleX != 1) || (oldScaleX && oldScaleX != scaleX)){ - target._scaleX = scaleX; - style.width = scaleX * target.width + "px"; - isStyleChange = true; - } - if((!oldScaleY && scaleY != 1) || (oldScaleY && oldScaleY != scaleY)){ - target._scaleY = scaleY; - style.height = scaleY * target.height + "px"; - isStyleChange = true; - } - if(isStyleChange){ - target.updateViewport(); - } - target.__webglWorldMatrix = target.__webglWorldMatrix||new Matrix(1, 0, 0, 1, 0, 0); - } - else if(target.parent){ - target.__webglWorldMatrix = target.__webglWorldMatrix||new Matrix(1, 0, 0, 1, 0, 0); - this._setConcatenatedMatrix(target, target.parent); - } - - if(target.alpha > 0) { - if(target.parent && target.parent.__webglRenderAlpha){ - target.__webglRenderAlpha = target.alpha * target.parent.__webglRenderAlpha; - } - else{ - target.__webglRenderAlpha = target.alpha; - } - } - }, - - /** - * @private - * @see Renderer#remove - */ - remove: function(target){ - var drawable = target.drawable; - var elem = drawable && drawable.domElement; - - if(elem){ - var parentElem = elem.parentNode; - if(parentElem){ - parentElem.removeChild(elem); - } - } - }, - - /** - * @private - * @see Renderer#clear - */ - clear: function(x, y, width, height){ - this.gl.clear(this.gl.COLOR_BUFFER_BIT); - }, - - /** - * @private - * @see Renderer#resize - */ - resize: function(width, height){ - if(this.width !== width || this.height !== height){ - var canvas = this.canvas; - var stage = this.stage; - var style = canvas.style; - - this.width = canvas.width = width; - this.height = canvas.height = height; - - style.width = stage.width * stage.scaleX + 'px'; - style.height = stage.height * stage.scaleY + 'px'; - - this.gl.viewport(0, 0, width, height); - - this.canvasHalfWidth = width * .5; - this.canvasHalfHeight = height * .5; - - this._uploadProjectionTransform(true); - } - }, - _renderBatches:function(){ - var gl = this.gl; - gl.bufferSubData(gl.ARRAY_BUFFER, 0, this.uint32Array.subarray(0, this.batchIndex * this.positionStride)); - var startIndex = 0; - var batchNum = 0; - var preTextureImage = null; - for(var i = 0;i < this.batchIndex;i ++){ - var sprite = this.sprites[i]; - if(preTextureImage && preTextureImage !== sprite.__textureImage){ - this._renderBatch(startIndex, i); - startIndex = i; - batchNum = 1; - } - preTextureImage = sprite.__textureImage; - } - this._renderBatch(startIndex, this.batchIndex); - this.batchIndex = 0; - }, - _renderBatch:function(start, end){ - var gl = this.gl; - var num = end - start; - if(num > 0){ - gl.bindTexture(gl.TEXTURE_2D, this._getTexture(this.sprites[start])); - gl.drawElements(gl.TRIANGLES, num * 6, gl.UNSIGNED_SHORT, start * 6 * 2); - } - }, - _uploadProjectionTransform:function(force){ - if(!this._projectionTransformElements||force){ - this._projectionTransformElements = new Float32Array([ - 1/this.canvasHalfWidth, 0, 0, - 0, -1/this.canvasHalfHeight, 0, - -1, 1, 1, - ]); - } - - this.gl.uniformMatrix3fv(this.u_projectionTransform, false, this._projectionTransformElements); - }, - _initShaders:function(){ - var VSHADER_SOURCE ='\ - attribute vec2 a_position;\n\ - attribute vec2 a_TexCoord;\n\ - attribute vec4 a_tint;\n\ - uniform mat3 u_projectionTransform;\n\ - varying vec2 v_TexCoord;\n\ - varying vec4 v_tint;\n\ - void main(){\n\ - gl_Position = vec4((u_projectionTransform * vec3(a_position, 1.0)).xy, 1.0, 1.0);\n\ - v_TexCoord = a_TexCoord;\n\ - v_tint = vec4(a_tint.rgb * a_tint.a, a_tint.a);\n\ - }\n\ - '; - - var FSHADER_SOURCE = '\n\ - precision mediump float;\n\ - uniform sampler2D u_Sampler;\n\ - varying vec2 v_TexCoord;\n\ - varying vec4 v_tint;\n\ - void main(){\n\ - gl_FragColor = texture2D(u_Sampler, v_TexCoord) * v_tint;\n\ - }\n\ - '; - - this.defaultShader = new Shader(this, { - v:VSHADER_SOURCE, - f:FSHADER_SOURCE - },{ - attributes:["a_position", "a_TexCoord", "a_tint"], - uniforms:["u_projectionTransform", "u_Sampler"] - }); - }, - _createVertexs:function(img, tx, ty, tw, th, x, y, w, h){ - var tempVertexs = this.__tempVertexs||[]; - var width = img.width; - var height = img.height; - - tw = tw/width; - th = th/height; - tx = tx/width; - ty = ty/height; - - w = w; - h = h; - x = x; - y = y; - - if(tw + tx > 1){ - tw = 1 - tx; - } - - if(th + ty > 1){ - th = 1 - ty; - } - - var index = 0; - tempVertexs[index++] = x; tempVertexs[index++] = y; tempVertexs[index++] = tx; tempVertexs[index++] = ty; - tempVertexs[index++] = x+w;tempVertexs[index++] = y; tempVertexs[index++] = tx+tw; tempVertexs[index++] = ty; - tempVertexs[index++] = x; tempVertexs[index++] = y+h; tempVertexs[index++] = tx;tempVertexs[index++] = ty+th; - tempVertexs[index++] = x+w;tempVertexs[index++] = y+h;tempVertexs[index++] = tx+tw;tempVertexs[index++] = ty+th; - - return tempVertexs; - }, - _setConcatenatedMatrix:function(view, ancestor){ - var mtx = view.__webglWorldMatrix; - var cos = 1, sin = 0, - rotation = view.rotation % 360, - pivotX = view.pivotX, pivotY = view.pivotY, - scaleX = view.scaleX, scaleY = view.scaleY, - transform = view.transform; - - if (transform) { - mtx.copy(transform); - } - else { - if(rotation){ - var r = rotation * DEG2RAD; - cos = Math.cos(r); - sin = Math.sin(r); - } - - var pos = view.getAlignPosition(); - - mtx.a = cos*scaleX; - mtx.b = sin*scaleX; - mtx.c = -sin*scaleY; - mtx.d = cos*scaleY; - mtx.tx = pos.x - mtx.a * pivotX - mtx.c * pivotY; - mtx.ty = pos.y - mtx.b * pivotX - mtx.d * pivotY; - } - - mtx.concat(ancestor.__webglWorldMatrix); - }, - _getTexture:function(sprite){ - var image = sprite.__textureImage; - var texture = this._cacheTexture[image.src]; - if(!texture){ - texture = this.activeShader.uploadTexture(image); - } - return texture; - } -}); - -/** - * @language=en - * shader - * @param {WebGLRenderer} renderer [description] - * @param {Object} source - * @param {String} source.v 顶点shader - * @param {String} source.f 片段shader - * @param {Object} attr - * @param {Array} attr.attributes attribute数组 - * @param {Array} attr.uniforms uniform数组 - */ -var Shader = function(renderer, source, attr){ - this.renderer = renderer; - this.gl = renderer.gl; - this.program = this._createProgram(this.gl, source.v, source.f); - - attr = attr||{}; - this.attributes = attr.attributes||[]; - this.uniforms = attr.uniforms||[]; -}; - -Shader.prototype = { - active:function(){ - var that = this; - var renderer = that.renderer; - var gl = that.gl; - var program = that.program; - - if(program && gl){ - renderer.activeShader = that; - gl.useProgram(program); - that.attributes.forEach(function(attribute){ - renderer[attribute] = gl.getAttribLocation(program, attribute); - gl.enableVertexAttribArray(renderer[attribute]); - }); - - that.uniforms.forEach(function(uniform){ - renderer[uniform] = gl.getUniformLocation(program, uniform); - }); - - if(that.width !== renderer.width || that.height !== renderer.height){ - that.width = renderer.width; - that.height = renderer.height; - renderer._uploadProjectionTransform(); - } - } - }, - uploadTexture:function(image){ - var gl = this.gl; - var renderer = this.renderer; - var texture = gl.createTexture(); - var u_Sampler = renderer.u_Sampler; - - gl.activeTexture(gl.TEXTURE0); - gl.bindTexture(gl.TEXTURE_2D, texture); - - // gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, 1); - gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, 1); - gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image); - - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); - gl.uniform1i(u_Sampler, 0); - gl.bindTexture(gl.TEXTURE_2D, null); - - this.renderer._cacheTexture[image.src] = texture; - return texture; - }, - _createProgram:function(gl, vshader, fshader){ - var vertexShader = this._createShader(gl, gl.VERTEX_SHADER, vshader); - var fragmentShader = this._createShader(gl, gl.FRAGMENT_SHADER, fshader); - if (!vertexShader || !fragmentShader) { - return null; - } - - var program = gl.createProgram(); - if (program) { - gl.attachShader(program, vertexShader); - gl.attachShader(program, fragmentShader); - - gl.linkProgram(program); - - gl.deleteShader(fragmentShader); - gl.deleteShader(vertexShader); - var linked = gl.getProgramParameter(program, gl.LINK_STATUS); - if (!linked) { - var error = gl.getProgramInfoLog(program); - console.log('Failed to link program: ' + error); - gl.deleteProgram(program); - return null; - } - } - return program; - }, - _createShader:function(gl, type, source){ - var shader = gl.createShader(type); - if(shader){ - gl.shaderSource(shader, source); - gl.compileShader(shader); - - var compiled = gl.getShaderParameter(shader, gl.COMPILE_STATUS); - if (!compiled) { - var error = gl.getShaderInfoLog(shader); - console.log('Failed to compile shader: ' + error); - gl.deleteShader(shader); - return null; - } - } - return shader; - } -}; -window.Hilo.WebGLRenderer = WebGLRenderer; -})(window); \ No newline at end of file +!function(t){t.Hilo||(t.Hilo={});var e=t.Hilo.Class,r=t.Hilo,i=t.Hilo.Renderer,a=t.Hilo.Matrix,n=Math.PI/180,s=e.create({Extends:i,Statics:{MAX_BATCH_NUM:2e3,ATTRIBUTE_NUM:5,isSupport:function(){if(void 0==this._isSupported){var t=document.createElement("canvas");t.getContext&&(t.getContext("webgl")||t.getContext("experimental-webgl"))?this._isSupported=!0:this._isSupported=!1}return this._isSupported},contextOptions:null},renderType:"webgl",gl:null,_isContextLost:!1,_cacheTexture:{},constructor:function(t){s.superclass.constructor.call(this,t);var e=this,r=s.contextOptions||{};this.gl=this.canvas.getContext("webgl",r)||this.canvas.getContext("experimental-webgl",r),this.maxBatchNum=s.MAX_BATCH_NUM,this.positionStride=4*s.ATTRIBUTE_NUM;var i=this.maxBatchNum*s.ATTRIBUTE_NUM*4,a=6*this.maxBatchNum;this.arrayBuffer=new ArrayBuffer(4*i),this.float32Array=new Float32Array(this.arrayBuffer),this.uint32Array=new Uint32Array(this.arrayBuffer),this.indexs=new Uint16Array(a);for(var n=0,o=0;n0)&&(t===this.stage&&this.clear(),!0)},draw:function(t){var e=t.width,r=t.height,i=(t.background,t.drawable),a=i&&i.image;if(a){var n=i.rect,s=n[2],o=n[3];e||r||(e=t.width=s,r=t.height=o),this.batchIndex>=this.maxBatchNum&&this._renderBatches();var h=this._createVertexs(a,n[0],n[1],s,o,0,0,e,r),c=this.batchIndex*this.positionStride,_=this.float32Array,l=this.uint32Array,d=(t.tint>>16)+(65280&t.tint)+((255&t.tint)<<16)+(255*t.__webglRenderAlpha<<24);_[c+0]=h[0],_[c+1]=h[1],_[c+2]=h[2],_[c+3]=h[3],l[c+4]=d,_[c+5]=h[4],_[c+6]=h[5],_[c+7]=h[6],_[c+8]=h[7],l[c+9]=d,_[c+10]=h[8],_[c+11]=h[9],_[c+12]=h[10],_[c+13]=h[11],l[c+14]=d,_[c+15]=h[12],_[c+16]=h[13],_[c+17]=h[14],_[c+18]=h[15],l[c+19]=d;for(var u=t.__webglWorldMatrix,f=0;f<4;f++){var g=_[c+5*f],x=_[c+5*f+1];_[c+5*f]=u.a*g+u.c*x+u.tx,_[c+5*f+1]=u.b*g+u.d*x+u.ty}t.__textureImage=a,this.sprites[this.batchIndex++]=t}},endDraw:function(t){t===this.stage&&this._renderBatches()},transform:function(t){var e=t.drawable;if(e&&e.domElement)return void r.setElementStyleByView(t);var i=t.scaleX,n=t.scaleY;if(t===this.stage){var s=this.canvas.style,o=t._scaleX,h=t._scaleY,c=!1;(!o&&1!=i||o&&o!=i)&&(t._scaleX=i,s.width=i*t.width+"px",c=!0),(!h&&1!=n||h&&h!=n)&&(t._scaleY=n,s.height=n*t.height+"px",c=!0),c&&t.updateViewport(),t.__webglWorldMatrix=t.__webglWorldMatrix||new a(1,0,0,1,0,0)}else t.parent&&(t.__webglWorldMatrix=t.__webglWorldMatrix||new a(1,0,0,1,0,0),this._setConcatenatedMatrix(t,t.parent));t.alpha>0&&(t.parent&&t.parent.__webglRenderAlpha?t.__webglRenderAlpha=t.alpha*t.parent.__webglRenderAlpha:t.__webglRenderAlpha=t.alpha)},remove:function(t){var e=t.drawable,r=e&&e.domElement;if(r){var i=r.parentNode;i&&i.removeChild(r)}},clear:function(t,e,r,i){this.gl.clear(this.gl.COLOR_BUFFER_BIT)},resize:function(t,e){if(this.width!==t||this.height!==e){var r=this.canvas,i=this.stage,a=r.style;this.width=r.width=t,this.height=r.height=e,a.width=i.width*i.scaleX+"px",a.height=i.height*i.scaleY+"px",this.gl.viewport(0,0,t,e),this.canvasHalfWidth=.5*t,this.canvasHalfHeight=.5*e,this._uploadProjectionTransform(!0)}},_renderBatches:function(){var t=this.gl;t.bufferSubData(t.ARRAY_BUFFER,0,this.uint32Array.subarray(0,this.batchIndex*this.positionStride));for(var e=0,r=0,i=null,a=0;a0&&(r.bindTexture(r.TEXTURE_2D,this._getTexture(this.sprites[t])),r.drawElements(r.TRIANGLES,6*i,r.UNSIGNED_SHORT,6*t*2))},_uploadProjectionTransform:function(t){this._projectionTransformElements&&!t||(this._projectionTransformElements=new Float32Array([1/this.canvasHalfWidth,0,0,0,-1/this.canvasHalfHeight,0,-1,1,1])),this.gl.uniformMatrix3fv(this.u_projectionTransform,!1,this._projectionTransformElements)},_initShaders:function(){var t=" attribute vec2 a_position;\n attribute vec2 a_TexCoord;\n attribute vec4 a_tint;\n uniform mat3 u_projectionTransform;\n varying vec2 v_TexCoord;\n varying vec4 v_tint;\n void main(){\n gl_Position = vec4((u_projectionTransform * vec3(a_position, 1.0)).xy, 1.0, 1.0);\n v_TexCoord = a_TexCoord;\n v_tint = vec4(a_tint.rgb * a_tint.a, a_tint.a);\n }\n ",e="\n precision mediump float;\n uniform sampler2D u_Sampler;\n varying vec2 v_TexCoord;\n varying vec4 v_tint;\n void main(){\n gl_FragColor = texture2D(u_Sampler, v_TexCoord) * v_tint;\n }\n ";this.defaultShader=new o(this,{v:t,f:e},{attributes:["a_position","a_TexCoord","a_tint"],uniforms:["u_projectionTransform","u_Sampler"]})},_createVertexs:function(t,e,r,i,a,n,s,o,h){var c=this.__tempVertexs||[],_=t.width,l=t.height;i/=_,a/=l,e/=_,r/=l,o=o,h=h,n=n,s=s,i+e>1&&(i=1-e),a+r>1&&(a=1-r);var d=0;return c[d++]=n,c[d++]=s,c[d++]=e,c[d++]=r,c[d++]=n+o,c[d++]=s,c[d++]=e+i,c[d++]=r,c[d++]=n,c[d++]=s+h,c[d++]=e,c[d++]=r+a,c[d++]=n+o,c[d++]=s+h,c[d++]=e+i,c[d++]=r+a,c},_setConcatenatedMatrix:function(t,e){var r=t.__webglWorldMatrix,i=1,a=0,s=t.rotation%360,o=t.pivotX,h=t.pivotY,c=t.scaleX,_=t.scaleY,l=t.transform;if(l)r.copy(l);else{if(s){var d=s*n;i=Math.cos(d),a=Math.sin(d)}var u=t.getAlignPosition();r.a=i*c,r.b=a*c,r.c=-a*_,r.d=i*_,r.tx=u.x-r.a*o-r.c*h,r.ty=u.y-r.b*o-r.d*h}r.concat(e.__webglWorldMatrix)},_getTexture:function(t){var e=t.__textureImage,r=this._cacheTexture[e.src];return r||(r=this.activeShader.uploadTexture(e)),r}}),o=function(t,e,r){this.renderer=t,this.gl=t.gl,this.program=this._createProgram(this.gl,e.v,e.f),r=r||{},this.attributes=r.attributes||[],this.uniforms=r.uniforms||[]};o.prototype={active:function(){var t=this,e=t.renderer,r=t.gl,i=t.program;i&&r&&(e.activeShader=t,r.useProgram(i),t.attributes.forEach(function(t){e[t]=r.getAttribLocation(i,t),r.enableVertexAttribArray(e[t])}),t.uniforms.forEach(function(t){e[t]=r.getUniformLocation(i,t)}),t.width===e.width&&t.height===e.height||(t.width=e.width,t.height=e.height,e._uploadProjectionTransform()))},uploadTexture:function(t){var e=this.gl,r=this.renderer,i=e.createTexture(),a=r.u_Sampler;return e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,i),e.pixelStorei(e.UNPACK_PREMULTIPLY_ALPHA_WEBGL,1),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,t),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.uniform1i(a,0),e.bindTexture(e.TEXTURE_2D,null),this.renderer._cacheTexture[t.src]=i,i},_createProgram:function(t,e,r){var i=this._createShader(t,t.VERTEX_SHADER,e),a=this._createShader(t,t.FRAGMENT_SHADER,r);if(!i||!a)return null;var n=t.createProgram();if(n){t.attachShader(n,i),t.attachShader(n,a),t.linkProgram(n),t.deleteShader(a),t.deleteShader(i);var s=t.getProgramParameter(n,t.LINK_STATUS);if(!s){var o=t.getProgramInfoLog(n);return console.log("Failed to link program: "+o),t.deleteProgram(n),null}}return n},_createShader:function(t,e,r){var i=t.createShader(e);if(i){t.shaderSource(i,r),t.compileShader(i);var a=t.getShaderParameter(i,t.COMPILE_STATUS);if(!a){var n=t.getShaderInfoLog(i);return console.log("Failed to compile shader: "+n),t.deleteShader(i),null}}return i}},t.Hilo.WebGLRenderer=s}(window); \ No newline at end of file diff --git a/build/standalone/hilo/tween/Ease.js b/build/standalone/hilo/tween/Ease.js index 4caf7535..efeda8d3 100644 --- a/build/standalone/hilo/tween/Ease.js +++ b/build/standalone/hilo/tween/Ease.js @@ -1,5 +1,5 @@ /** - * Hilo 1.5.0 for standalone + * Hilo 1.6.0 for standalone * Copyright 2016 alibaba.com * Licensed under the MIT License */ diff --git a/build/standalone/hilo/tween/Ease.min.js b/build/standalone/hilo/tween/Ease.min.js index 8417c959..3405ffe1 100644 --- a/build/standalone/hilo/tween/Ease.min.js +++ b/build/standalone/hilo/tween/Ease.min.js @@ -1,275 +1,6 @@ /** - * Hilo 1.5.0 for standalone + * Hilo 1.6.0 for standalone * Copyright 2016 alibaba.com * Licensed under the MIT License */ -/** - * Hilo 1.5.0 for standalone - * Copyright 2016 alibaba.com - * Licensed under the MIT License - */ -(function(window){ -if(!window.Hilo) window.Hilo = {}; - - -/** - * @language=en - * @class Ease class provides multiple easing functions for Tween. - * @module hilo/tween/Ease - * @static - */ -var Ease = (function(){ - -function createEase(obj, easeInFn, easeOutFn, easeInOutFn, easeNoneFn){ - obj = obj || {}; - easeInFn && (obj.EaseIn = easeInFn); - easeOutFn && (obj.EaseOut = easeOutFn); - easeInOutFn && (obj.EaseInOut = easeInOutFn); - easeNoneFn && (obj.EaseNone = easeNoneFn); - return obj; -} - -/** - * @language=en - * Linear easing function.Include EaseNone. - */ -var Linear = createEase(null, null, null, null, function(k){ - return k; -}); - -/** - * @language=en - * Quad easing function.Include EaseIn, EaseOut, EaseInOut. - */ -var Quad = createEase(null, - function(k){ - return k * k; - }, - - function(k){ - return - k * (k - 2); - }, - - function(k){ - return ((k *= 2) < 1) ? 0.5 * k * k : -0.5 * (--k * (k - 2) - 1); - } -); - -/** - * @language=en - * Cubic easing function.Include EaseIn, EaseOut, EaseInOut. - */ -var Cubic = createEase(null, - function(k){ - return k * k * k; - }, - - function(k){ - return --k * k * k + 1; - }, - - function(k){ - return ((k *= 2) < 1) ? 0.5 * k * k * k : 0.5 * ((k -= 2) * k * k + 2); - } -); - -/** - * @language=en - * Quart easing function.Include EaseIn, EaseOut, EaseInOut. - */ -var Quart = createEase(null, - function(k){ - return k * k * k * k; - }, - - function(k){ - return -(--k * k * k * k - 1); - }, - - function(k){ - return ((k *= 2) < 1) ? 0.5 * k * k * k * k : - 0.5 * ((k -= 2) * k * k * k - 2); - } -); - -/** - * @language=en - * Quint easing function.Include EaseIn, EaseOut, EaseInOut. - */ -var Quint = createEase(null, - function(k){ - return k * k * k * k * k; - }, - - function(k){ - return (k = k - 1) * k * k * k * k + 1; - }, - - function(k){ - return ((k *= 2) < 1) ? 0.5 * k * k * k * k * k : 0.5 * ((k -= 2) * k * k * k * k + 2); - } -); - -var math = Math, - PI = math.PI, HALF_PI = PI * 0.5, - sin = math.sin, cos = math.cos, - pow = math.pow, sqrt = math.sqrt; - -/** - * @language=en - * Sine easing function.Include EaseIn, EaseOut, EaseInOut. - */ -var Sine = createEase(null, - function(k){ - return -cos(k * HALF_PI) + 1; - }, - - function(k){ - return sin(k * HALF_PI); - }, - - function(k){ - return -0.5 * (cos(PI * k) - 1); - } -); - -/** - * @language=en - * Expo easing function.Include EaseIn, EaseOut, EaseInOut. - */ -var Expo = createEase(null, - function(k){ - return k == 0 ? 0 : pow(2, 10 * (k - 1)); - }, - - function(k){ - return k == 1 ? 1 : -pow(2, -10 * k) + 1; - }, - - function(k){ - if(k == 0 || k == 1) return k; - if((k *= 2) < 1) return 0.5 * pow(2, 10 * (k - 1)); - return 0.5 * (-pow(2, - 10 * (k - 1)) + 2); - } -); - -/** - * @language=en - * Circ easing function.Include EaseIn, EaseOut, EaseInOut. - */ -var Circ = createEase(null, - function(k){ - return -(sqrt(1 - k * k) - 1); - }, - - function(k){ - return sqrt(1 - (--k * k)); - }, - - function(k){ - if((k /= 0.5) < 1) return - 0.5 * (sqrt(1 - k * k) - 1); - return 0.5 * (sqrt(1 - (k -= 2) * k) + 1); - } -); - -/** - * @language=en - * Elastic easing function.Include EaseIn, EaseOut, EaseInOut. - */ -var Elastic = createEase( - { - a: 1, - p: 0.4, - s: 0.1, - - config: function(amplitude, period){ - Elastic.a = amplitude; - Elastic.p = period; - Elastic.s = period / (2 * PI) * Math.asin(1 / amplitude) || 0; - } - }, - - function(k){ - return -(Elastic.a * pow(2, 10 * (k -= 1)) * sin((k - Elastic.s) * (2 * PI) / Elastic.p)); - }, - - function(k){ - return (Elastic.a * pow(2, -10 * k) * sin((k - Elastic.s) * (2 * PI) / Elastic.p) + 1); - }, - - function(k){ - return ((k *= 2) < 1) ? -0.5 * (Elastic.a * pow(2, 10 * (k -= 1)) * sin((k - Elastic.s) * (2 * PI) / Elastic.p)) : - Elastic.a * pow(2, -10 * (k -= 1)) * sin((k - Elastic.s) * (2 * PI) / Elastic.p) * 0.5 + 1; - } -); - -/** - * @language=en - * Back easing function.Include EaseIn, EaseOut, EaseInOut. - */ -var Back = createEase( - { - o: 1.70158, - s: 2.59491, - - config: function(overshoot){ - Back.o = overshoot; - Back.s = overshoot * 1.525; - } - }, - - function(k){ - return k * k * ((Back.o + 1) * k - Back.o); - }, - - function(k){ - return (k = k - 1) * k * ((Back.o + 1) * k + Back.o) + 1; - }, - - function(k){ - return ((k *= 2) < 1) ? 0.5 * (k * k * ((Back.s + 1) * k - Back.s)) : 0.5 * ((k -= 2) * k * ((Back.s + 1) * k + Back.s) + 2); - } -); - -/** - * @language=en - * Bounce easing function.Include EaseIn, EaseOut, EaseInOut. - */ -var Bounce = createEase(null, - function(k){ - return 1 - Bounce.EaseOut(1 - k); - }, - - function(k){ - if((k /= 1) < 0.36364){ - return 7.5625 * k * k; - }else if(k < 0.72727){ - return 7.5625 * (k -= 0.54545) * k + 0.75; - }else if(k < 0.90909){ - return 7.5625 * (k -= 0.81818) * k + 0.9375; - }else{ - return 7.5625 * (k -= 0.95455) * k + 0.984375; - } - }, - - function(k){ - return k < 0.5 ? Bounce.EaseIn(k * 2) * 0.5 : Bounce.EaseOut(k * 2 - 1) * 0.5 + 0.5; - } -); - -return { - Linear: Linear, - Quad: Quad, - Cubic: Cubic, - Quart: Quart, - Quint: Quint, - Sine: Sine, - Expo: Expo, - Circ: Circ, - Elastic: Elastic, - Back: Back, - Bounce: Bounce -}; - -})(); -window.Hilo.Ease = Ease; -})(window); \ No newline at end of file +!function(n){n.Hilo||(n.Hilo={});var u=function(){function n(n,u,t,r,o){return n=n||{},u&&(n.EaseIn=u),t&&(n.EaseOut=t),r&&(n.EaseInOut=r),o&&(n.EaseNone=o),n}var u=n(null,null,null,null,function(n){return n}),t=n(null,function(n){return n*n},function(n){return-n*(n-2)},function(n){return(n*=2)<1?.5*n*n:-.5*(--n*(n-2)-1)}),r=n(null,function(n){return n*n*n},function(n){return--n*n*n+1},function(n){return(n*=2)<1?.5*n*n*n:.5*((n-=2)*n*n+2)}),o=n(null,function(n){return n*n*n*n},function(n){return-(--n*n*n*n-1)},function(n){return(n*=2)<1?.5*n*n*n*n:-.5*((n-=2)*n*n*n-2)}),i=n(null,function(n){return n*n*n*n*n},function(n){return(n-=1)*n*n*n*n+1},function(n){return(n*=2)<1?.5*n*n*n*n*n:.5*((n-=2)*n*n*n*n+2)}),e=Math,c=e.PI,f=.5*c,l=e.sin,s=e.cos,a=e.pow,E=e.sqrt,p=n(null,function(n){return-s(n*f)+1},function(n){return l(n*f)},function(n){return-.5*(s(c*n)-1)}),I=n(null,function(n){return 0==n?0:a(2,10*(n-1))},function(n){return 1==n?1:-a(2,-10*n)+1},function(n){return 0==n||1==n?n:(n*=2)<1?.5*a(2,10*(n-1)):.5*(-a(2,-10*(n-1))+2)}),O=n(null,function(n){return-(E(1-n*n)-1)},function(n){return E(1- --n*n)},function(n){return(n/=.5)<1?-.5*(E(1-n*n)-1):.5*(E(1-(n-=2)*n)+1)}),w=n({a:1,p:.4,s:.1,config:function(n,u){w.a=n,w.p=u,w.s=u/(2*c)*Math.asin(1/n)||0}},function(n){return-(w.a*a(2,10*(n-=1))*l((n-w.s)*(2*c)/w.p))},function(n){return w.a*a(2,-10*n)*l((n-w.s)*(2*c)/w.p)+1},function(n){return(n*=2)<1?-.5*(w.a*a(2,10*(n-=1))*l((n-w.s)*(2*c)/w.p)):w.a*a(2,-10*(n-=1))*l((n-w.s)*(2*c)/w.p)*.5+1}),H=n({o:1.70158,s:2.59491,config:function(n){H.o=n,H.s=1.525*n}},function(n){return n*n*((H.o+1)*n-H.o)},function(n){return(n-=1)*n*((H.o+1)*n+H.o)+1},function(n){return(n*=2)<1?.5*(n*n*((H.s+1)*n-H.s)):.5*((n-=2)*n*((H.s+1)*n+H.s)+2)}),Q=n(null,function(n){return 1-Q.EaseOut(1-n)},function(n){return(n/=1)<.36364?7.5625*n*n:n<.72727?7.5625*(n-=.54545)*n+.75:n<.90909?7.5625*(n-=.81818)*n+.9375:7.5625*(n-=.95455)*n+.984375},function(n){return n<.5?.5*Q.EaseIn(2*n):.5*Q.EaseOut(2*n-1)+.5});return{Linear:u,Quad:t,Cubic:r,Quart:o,Quint:i,Sine:p,Expo:I,Circ:O,Elastic:w,Back:H,Bounce:Q}}();n.Hilo.Ease=u}(window); \ No newline at end of file diff --git a/build/standalone/hilo/tween/Tween.js b/build/standalone/hilo/tween/Tween.js index f97e721b..71f29d9c 100644 --- a/build/standalone/hilo/tween/Tween.js +++ b/build/standalone/hilo/tween/Tween.js @@ -1,5 +1,5 @@ /** - * Hilo 1.5.0 for standalone + * Hilo 1.6.0 for standalone * Copyright 2016 alibaba.com * Licensed under the MIT License */ diff --git a/build/standalone/hilo/tween/Tween.min.js b/build/standalone/hilo/tween/Tween.min.js index 2aaf0bc1..a0416f42 100644 --- a/build/standalone/hilo/tween/Tween.min.js +++ b/build/standalone/hilo/tween/Tween.min.js @@ -1,460 +1,6 @@ /** - * Hilo 1.5.0 for standalone + * Hilo 1.6.0 for standalone * Copyright 2016 alibaba.com * Licensed under the MIT License */ -/** - * Hilo 1.5.0 for standalone - * Copyright 2016 alibaba.com - * Licensed under the MIT License - */ -(function(window){ -if(!window.Hilo) window.Hilo = {}; -var Class = window.Hilo.Class; - - -/** - * @language=en - * - *
- * Demo: - *
- * ticker.addTick(Hilo.Tween);//Tween works after being added to ticker
- *
- * var view = new View({x:5, y:10});
- * Hilo.Tween.to(view, {
- *     x:100,
- *     y:20,
- *     alpha:0
- * }, {
- *     duration:1000,
- *     delay:500,
- *     ease:Hilo.Ease.Quad.EaseIn,
- *     onComplete:function(){
- *         console.log('complete');
- *     }
- * });
- * 
- * @class Tween class makes tweening (easing, slow motion). - * @param {Object} target Tween target object. - * @param {Object} fromProps Beginning properties of target tweening object. - * @param {Object} toProps Ending properties of target tweening object. - * @param {Object} params Tweening parameters, include all writable Tween class properties. - * @module hilo/tween/Tween - * @requires hilo/core/Class - * @property {Object} target Tween target object, readonly! - * @property {Int} duration Tweening duration, measure in ms. - * @property {Int} delay Tweenning delay time, measure in ms. - * @property {Boolean} paused Is tweening paused, default value is false. - * @property {Boolean} loop Does tweening loop, default value is false. - * @property {Boolean} reverse Does tweening reverse, default value is false. - * @property {Int} repeat Repeat times of tweening, default value is 0. - * @property {Int} repeatDelay Delay time of repeating tweening, measure in ms. - * @property {Function} ease Tweening transform function, default value is null. - * @property {Int} time Time that tweening taken, measure in ms, readonly! - * @property {Function} onStart Function invoked on the beginning of tweening. Require 1 parameter: tween. default value is null. - * @property {Function} onUpdate Function invoked on tweening update. Require 2 parameters: ratio, tween. default value is null. - * @property {Function} onComplete Function invoked on the end of tweening. Require 1 parameter: tween. default value is null. - */ -var Tween = (function(){ - -function now(){ - return +new Date(); -} - -return Class.create(/** @lends Tween.prototype */{ - constructor: function(target, fromProps, toProps, params){ - var me = this; - - me.target = target; - me._startTime = 0; - me._seekTime = 0; - me._pausedTime = 0; - me._pausedStartTime = 0; - me._reverseFlag = 1; - me._repeatCount = 0; - - //no fromProps if pass 3 arguments - if(arguments.length == 3){ - params = toProps; - toProps = fromProps; - fromProps = null; - } - - for(var p in params) me[p] = params[p]; - me._fromProps = fromProps; - me._toProps = toProps; - - //for old version compatiblity - if(!params.duration && params.time){ - me.duration = params.time || 0; - me.time = 0; - } - }, - - target: null, - duration: 1000, - delay: 0, - paused: false, - loop: false, - reverse: false, - repeat: 0, - repeatDelay: 0, - ease: null, - time: 0, //ready only - - isStart:false, - isComplete:false, - onStart: null, - onUpdate: null, - onComplete: null, - - /** - * @language=en - * Set beginning properties and ending properties of tweening object. - * @param {Object} fromProps Beginning properties of target tweening object. - * @param {Object} toProps Ending properties of target tweening object. - * @returns {Tween} Current Tween, for chain calls. - */ - setProps: function(fromProps, toProps){ - var me = this, target = me.target, - propNames = fromProps || toProps, - from = me._fromProps = {}, to = me._toProps = {}; - - fromProps = fromProps || target; - toProps = toProps || target; - - for(var p in propNames){ - to[p] = toProps[p] || 0; - target[p] = from[p] = fromProps[p] || 0; - } - return me; - }, - - /** - * @language=en - * Starting the tweening. - * @returns {Tween} Current Tween, for chain calls. - */ - start: function(){ - var me = this; - me._startTime = now() + me.delay; - me._seekTime = 0; - me._pausedTime = 0; - me._reverseFlag = 1; - me._repeatCount = 0; - me.paused = false; - me.isStart = false; - me.isComplete = false; - Tween.add(me); - return me; - }, - - /** - * @language=en - * Stop the tweening. - * @returns {Tween} Current Tween, for chain calls. - */ - stop: function(){ - Tween.remove(this); - return this; - }, - - /** - * @language=en - * Pause the tweening. - * @returns {Tween} Current Tween, for chain calls. - */ - pause: function(){ - var me = this; - me.paused = true; - me._pausedStartTime = now(); - return me; - }, - - /** - * @language=en - * Continue to play the tweening. - * @returns {Tween} Current Tween, for chain calls. - */ - resume: function(){ - var me = this; - me.paused = false; - if(me._pausedStartTime) me._pausedTime += now() - me._pausedStartTime; - me._pausedStartTime = 0; - return me; - }, - - /** - * @language=en - * Tween jumps to some point. - * @param {Number} time The time to jump to, range from 0 to duration. - * @param {Boolean} pause Is paused. - * @returns {Tween} Current Tween, for chain calls. - */ - seek: function(time, pause){ - var me = this, current = now(); - me._startTime = current; - me._seekTime = time; - me._pausedTime = 0; - if(pause !== undefined) me.paused = pause; - me._update(current, true); - Tween.add(me); - return me; - }, - - /** - * @language=en - * Link next Tween. The beginning time of next Tween depends on the delay value. If delay is a string that begins with '+' or '-', next Tween will begin at (delay) ms after or before the current tween is ended. If delay is out of previous situation, next Tween will begin at (delay) ms after the beginning point of current Tween. - * @param {Tween} tween Tween to link. - * @returns {Tween} next Tween, for chain calls. - */ - link: function(tween){ - var me = this, delay = tween.delay, startTime = me._startTime; - - var plus, minus; - if(typeof delay === 'string'){ - plus = delay.indexOf('+') == 0; - minus = delay.indexOf('-') == 0; - delay = plus || minus ? Number(delay.substr(1)) * (plus ? 1 : -1) : Number(delay); - } - tween.delay = delay; - tween._startTime = plus || minus ? startTime + me.duration + delay : startTime + delay; - - me._next = tween; - Tween.remove(tween); - return tween; - }, - - /** - * @language=en - * Private render method inside Tween class. - * @private - */ - _render: function(ratio){ - var me = this, target = me.target, fromProps = me._fromProps, p; - for(p in fromProps) target[p] = fromProps[p] + (me._toProps[p] - fromProps[p]) * ratio; - }, - - /** - * @language=en - * Private update method inside Tween class. - * @private - */ - _update: function(time, forceUpdate){ - var me = this; - if(me.paused && !forceUpdate) return; - if(me.isComplete) return true; - - //elapsed time - var elapsed = time - me._startTime - me._pausedTime + me._seekTime; - if(elapsed < 0) return; - - //elapsed ratio - var ratio = elapsed / me.duration, complete = false, callback; - ratio = ratio <= 0 ? 0 : ratio >= 1 ? 1 : ratio; - var easeRatio = me.ease ? me.ease(ratio) : ratio; - - if(me.reverse && me.isStart){ - //backward - if(me._reverseFlag < 0) { - ratio = 1 - ratio; - easeRatio = 1 - easeRatio; - } - //forward - if(ratio < 1e-7){ - //repeat complete or not loop - if((me.repeat > 0 && me._repeatCount++ >= me.repeat) || (me.repeat == 0 && !me.loop)){ - complete = true; - }else{ - me._startTime = now(); - me._pausedTime = 0; - me._reverseFlag *= -1; - } - } - } - - //start callback - if(!me.isStart) { - me.setProps(me._fromProps, me._toProps); - me.isStart = true; - if(me.onStart){ - me.onStart.call(me, me); - } - } - me.time = elapsed; - - //render & update callback - me._render(easeRatio); - (callback = me.onUpdate) && callback.call(me, ratio, me); - - //check if complete - if(ratio >= 1){ - if(me.reverse){ - me._startTime = now(); - me._pausedTime = 0; - me._reverseFlag *= -1; - }else if(me.loop || me.repeat > 0 && me._repeatCount++ < me.repeat){ - me._startTime = now() + me.repeatDelay; - me._pausedTime = 0; - }else{ - me.isComplete = true; - } - } - - //next tween - var next = me._next; - if(next && next.time <= 0){ - var nextStartTime = next._startTime; - if(nextStartTime > 0 && nextStartTime <= time){ - //parallel tween - next._render(ratio); - next.time = elapsed; - Tween.add(next); - }else if(me.isComplete && (nextStartTime < 0 || nextStartTime > time)){ - //next tween - next.start(); - } - } - - //complete - if(me.isComplete){ - (callback = me.onComplete) && callback.call(me, me); - return true; - } - }, - - Statics: /** @lends Tween */ { - /** - * @language=en - * @private - */ - _tweens: [], - - /** - * @language=en - * Update all Tween instances. - * @returns {Object} Tween。 - */ - tick: function(){ - var tweens = Tween._tweens, tween, i, len = tweens.length; - - for(i = 0; i < len; i++){ - tween = tweens[i]; - if(tween && tween._update(now())){ - tweens.splice(i, 1); - i--; - } - } - return Tween; - }, - - /** - * @language=en - * Add a Tween instance. - * @param {Tween} tween Tween object to add. - * @returns {Object} Tween。 - */ - add: function(tween){ - var tweens = Tween._tweens; - if(tweens.indexOf(tween) == -1) tweens.push(tween); - return Tween; - }, - - /** - * @language=en - * Remove one Tween target. - * @param {Tween|Object|Array} tweenOrTarget Tween object, target object or an array of object to remove - * @returns {Object} Tween。 - */ - remove: function(tweenOrTarget){ - var i, l; - if(tweenOrTarget instanceof Array){ - for(i = 0, l = tweenOrTarget.length;i < l;i ++){ - Tween.remove(tweenOrTarget[i]); - } - return Tween; - } - - var tweens = Tween._tweens; - if(tweenOrTarget instanceof Tween){ - i = tweens.indexOf(tweenOrTarget); - if(i > -1) tweens.splice(i, 1); - }else{ - for(i = 0; i < tweens.length; i++){ - if(tweens[i].target === tweenOrTarget){ - tweens.splice(i, 1); - i--; - } - } - } - - return Tween; - }, - - /** - * @language=en - * Remove all Tween instances. - * @returns {Object} Tween。 - */ - removeAll: function(){ - Tween._tweens.length = 0; - return Tween; - }, - - /** - * @language=en - * Create a tween, make target object easing from beginning properties to ending properties. - * @param {Object|Array} target Tweening target or tweening target array. - * @param fromProps Beginning properties of target tweening object. - * @param toProps Ending properties of target tweening object. - * @param params Tweening parameters. - * @returns {Tween|Array} An tween instance or an array of tween instance. - */ - fromTo: function(target, fromProps, toProps, params){ - params = params || {}; - var isArray = target instanceof Array; - target = isArray ? target : [target]; - - var tween, i, stagger = params.stagger, tweens = []; - for(i = 0; i < target.length; i++){ - tween = new Tween(target[i], fromProps, toProps, params); - if(stagger) tween.delay = (params.delay || 0) + (i * stagger || 0); - tween.start(); - tweens.push(tween); - } - - return isArray?tweens:tween; - }, - - /** - * @language=en - * Create a tween, make target object easing from current properties to ending properties. - * @param {Object|Array} target Tweening target or tweening target array. - * @param toProps Ending properties of target tweening object. - * @param params Tweening parameters. - * @returns {Tween|Array} An tween instance or an array of tween instance. - */ - to: function(target, toProps, params){ - return Tween.fromTo(target, null, toProps, params); - }, - - /** - * @language=en - * Create a tween, make target object easing from beginning properties to current properties. - * @param {Object|Array} target Tweening target or tweening target array. - * @param fromProps Beginning properties of target tweening object. - * @param params Tweening parameters. - * @returns {Tween|Array} An tween instance or an array of tween instance. - */ - from: function(target, fromProps, params){ - return Tween.fromTo(target, fromProps, null, params); - } - } - -}); - -})(); - -window.Hilo.Tween = Tween; -})(window); \ No newline at end of file +!function(e){e.Hilo||(e.Hilo={});var t=e.Hilo.Class,r=function(){function e(){return+new Date}return t.create({constructor:function(e,t,r,a){var n=this;n.target=e,n._startTime=0,n._seekTime=0,n._pausedTime=0,n._pausedStartTime=0,n._reverseFlag=1,n._repeatCount=0,3==arguments.length&&(a=r,r=t,t=null);for(var i in a)n[i]=a[i];n._fromProps=t,n._toProps=r,!a.duration&&a.time&&(n.duration=a.time||0,n.time=0)},target:null,duration:1e3,delay:0,paused:!1,loop:!1,reverse:!1,repeat:0,repeatDelay:0,ease:null,time:0,isStart:!1,isComplete:!1,onStart:null,onUpdate:null,onComplete:null,setProps:function(e,t){var r=this,a=r.target,n=e||t,i=r._fromProps={},s=r._toProps={};e=e||a,t=t||a;for(var o in n)s[o]=t[o]||0,a[o]=i[o]=e[o]||0;return r},start:function(){var t=this;return t._startTime=e()+t.delay,t._seekTime=0,t._pausedTime=0,t._reverseFlag=1,t._repeatCount=0,t.paused=!1,t.isStart=!1,t.isComplete=!1,r.add(t),t},stop:function(){return r.remove(this),this},pause:function(){var t=this;return t.paused=!0,t._pausedStartTime=e(),t},resume:function(){var t=this;return t.paused=!1,t._pausedStartTime&&(t._pausedTime+=e()-t._pausedStartTime),t._pausedStartTime=0,t},seek:function(t,a){var n=this,i=e();return n._startTime=i,n._seekTime=t,n._pausedTime=0,void 0!==a&&(n.paused=a),n._update(i,!0),r.add(n),n},link:function(e){var t,a,n=this,i=e.delay,s=n._startTime;return"string"==typeof i&&(t=0==i.indexOf("+"),a=0==i.indexOf("-"),i=t||a?Number(i.substr(1))*(t?1:-1):Number(i)),e.delay=i,e._startTime=t||a?s+n.duration+i:s+i,n._next=e,r.remove(e),e},_render:function(e){var t,r=this,a=r.target,n=r._fromProps;for(t in n)a[t]=n[t]+(r._toProps[t]-n[t])*e},_update:function(t,a){var n=this;if(!n.paused||a){if(n.isComplete)return!0;var i=t-n._startTime-n._pausedTime+n._seekTime;if(!(i<0)){var s,o=i/n.duration,u=!1;o=o<=0?0:o>=1?1:o;var p=n.ease?n.ease(o):o;n.reverse&&n.isStart&&(n._reverseFlag<0&&(o=1-o,p=1-p),o<1e-7&&(n.repeat>0&&n._repeatCount++>=n.repeat||0==n.repeat&&!n.loop?u=!0:(n._startTime=e(),n._pausedTime=0,n._reverseFlag*=-1))),n.isStart||(n.setProps(n._fromProps,n._toProps),n.isStart=!0,n.onStart&&n.onStart.call(n,n)),n.time=i,n._render(p),(s=n.onUpdate)&&s.call(n,o,n),o>=1&&(n.reverse?(n._startTime=e(),n._pausedTime=0,n._reverseFlag*=-1):n.loop||n.repeat>0&&n._repeatCount++0&&m<=t?(l._render(o),l.time=i,r.add(l)):n.isComplete&&(m<0||m>t)&&l.start()}return n.isComplete?((s=n.onComplete)&&s.call(n,n),!0):void 0}}},Statics:{_tweens:[],tick:function(){var t,a,n=r._tweens,i=n.length;for(a=0;a-1&&n.splice(t,1);else for(t=0;t - *
  • image - 纹理集图片。必需。
  • - *
  • width - 纹理集图片宽度。若frames数据为Object时,此属性必需。
  • - *
  • height - 纹理集图片高度。若frames数据为Object时,此属性必需。
  • - *
  • frames - 纹理集帧数据,可以是Array或Object。必需。 - *
      - *
    • 若为Array,则每项均为一个纹理图片帧数据,如:[[0, 0, 50, 50], [0, 50, 50, 50]。
    • - *
    • 若为Object,则需包含frameWidth(帧宽)、frameHeight(帧高)、numFrames(帧数) 属性。
    • - *
    - *
  • - *
  • sprites - 纹理集精灵动画定义,其每个值均定义一个精灵。为Object对象。可选。 - *
      - *
    • 若为Number,即此精灵只包含一帧,此帧为帧数据中索引为当前值的帧。如:sprites:{'foo':1}。
    • - *
    • 若为Array,则每项均为一个帧的索引值。如:sprites:{'foo':[0, 1, 2, 3]}。
    • - *
    • 若为Object,则需包含from(起始帧索引值)、to(末帧索引值) 属性。
    • - *
    - *
  • - * - * @module hilo/util/TextureAtlas - * @requires hilo/core/Class - */ -var TextureAtlas = (function(){ - -return Class.create(/** @lends TextureAtlas.prototype */{ - constructor: function(atlasData){ - this._frames = parseTextureFrames(atlasData); - this._sprites = parseTextureSprites(atlasData, this._frames); - }, - - _frames: null, - _sprites: null, - - /** - * @language=en - * 获取指定索引位置index的帧数据。 - * @param {Int} index 要获取帧的索引位置。 - * @returns {Object} 帧数据。 - */ - getFrame: function(index){ - var frames = this._frames; - return frames && frames[index]; - }, - - /** - * @language=en - * 获取指定id的精灵数据。 - * @param {String} id 要获取精灵的id。 - * @returns {Object} 精灵数据。 - */ - getSprite: function(id){ - var sprites = this._sprites; - return sprites && sprites[id]; - }, - - Statics: /** @lends TextureAtlas */ { - /** - * @language=en - * Shorthand method to create spirte frames - * @param {String|Array} name Name of one animation|a group of animation - * @param {String} frames Frames message, eg:"0-5" means frame 0 to frame 5. - * @param {Number} w The width of each frame. - * @param {Number} h The height of each frame. - * @param {Boolean} loop Is play in loop. - * @param {Number} duration The time between each frame. default value is 1 (Frame), but if timeBased is true, default value will be duration(milli-second). - * @example - * //demo1 make one animation - * createSpriteFrames("walk", "0-5,8,9", meImg, 55, 88, true, 1); - * //demo2 make a group of animation - * createSpriteFrames([ - * ["walk", "0-5,8,9", meImg, 55, 88, true, 1], - * ["jump", "0-5", meImg, 55, 88, false, 1] - * ]); - */ - createSpriteFrames:function(name, frames, img, w, h, loop, duration){ - var i, l; - if(Object.prototype.toString.call(name) === "[object Array]"){ - var res = []; - for(i = 0, l = name.length;i < l;i ++){ - res = res.concat(this.createSpriteFrames.apply(this, name[i])); - } - return res; - } - else{ - if(typeof(frames) === "string"){ - var all = frames.split(","); - frames = []; - for(var j = 0, jl = all.length;j < jl;j ++){ - var temp = all[j].split("-"); - if(temp.length == 1){ - frames.push(parseInt(temp[0])); - } - else{ - for(i = parseInt(temp[0]), l = parseInt(temp[1]);i <= l;i ++){ - frames.push(i); - } - } - } - } - - var col = Math.floor(img.width/w); - for(i = 0;i < frames.length;i ++){ - var n = frames[i]; - frames[i] = { - rect:[w*(n%col), h*Math.floor(n/col), w, h], - image:img, - duration:duration - }; - } - frames[0].name = name; - if(loop){ - frames[frames.length-1].next = name; - } - else{ - frames[frames.length-1].stop = true; - } - return frames; - } - } - } -}); - -/** - * @language=en - * Parse texture frames - * @private - */ -function parseTextureFrames(atlasData){ - var i, len; - var frameData = atlasData.frames; - if(!frameData) return null; - - var frames = [], obj; - - if(frameData instanceof Array){ //frames by array - for(i = 0, len = frameData.length; i < len; i++){ - obj = frameData[i]; - frames[i] = { - image: atlasData.image, - rect: obj - }; - } - }else{ //frames by object - var frameWidth = frameData.frameWidth; - var frameHeight = frameData.frameHeight; - var cols = atlasData.width / frameWidth | 0; - var rows = atlasData.height / frameHeight | 0; - var numFrames = frameData.numFrames || cols * rows; - for(i = 0; i < numFrames; i++){ - frames[i] = { - image: atlasData.image, - rect: [i%cols*frameWidth, (i/cols|0)*frameHeight, frameWidth, frameHeight] - }; - } - } - - return frames; -} - -/** - * @language=en - * Parse texture sprites - * @private - */ -function parseTextureSprites(atlasData, frames){ - var i, len; - var spriteData = atlasData.sprites; - if(!spriteData) return null; - - var sprites = {}, sprite, spriteFrames, spriteFrame; - - for(var s in spriteData){ - sprite = spriteData[s]; - if(isNumber(sprite)){ //single frame - spriteFrames = translateSpriteFrame(frames[sprite]); - }else if(sprite instanceof Array){ //frames by array - spriteFrames = []; - for(i = 0, len = sprite.length; i < len; i++){ - var spriteObj = sprite[i], frameObj; - if(isNumber(spriteObj)){ - spriteFrame = translateSpriteFrame(frames[spriteObj]); - }else{ - frameObj = spriteObj.rect; - if(isNumber(frameObj)) frameObj = frames[spriteObj.rect]; - spriteFrame = translateSpriteFrame(frameObj, spriteObj); - } - spriteFrames[i] = spriteFrame; - } - }else{ //frames by object - spriteFrames = []; - for(i = sprite.from; i <= sprite.to; i++){ - spriteFrames[i - sprite.from] = translateSpriteFrame(frames[i], sprite[i]); - } - } - sprites[s] = spriteFrames; - } - - return sprites; -} - -function translateSpriteFrame(frameObj, spriteObj){ - var spriteFrame = { - image: frameObj.image, - rect: frameObj.rect - }; - - if(spriteObj){ - spriteFrame.name = spriteObj.name || null; - spriteFrame.duration = spriteObj.duration || 0; - spriteFrame.stop = !!spriteObj.stop; - spriteFrame.next = spriteObj.next || null; - } - - return spriteFrame; -} - -function isNumber(value){ - return typeof value === 'number'; -} - -})(); -window.Hilo.TextureAtlas = TextureAtlas; -})(window); \ No newline at end of file +!function(r){r.Hilo||(r.Hilo={});var t=r.Hilo.Class,e=function(){function r(r){var t,e,n=r.frames;if(!n)return null;var a,i=[];if(n instanceof Array)for(t=0,e=n.length;t= this._targetFPS){ - this._measuredFPS = 1000 / (this._tickTime / this._tickCount) + 0.5 >> 0; - this._tickCount = 0; - this._tickTime = 0; - }else{ - this._tickTime += startTime - this._lastTime; - } - this._lastTime = startTime; - - var tickersCopy = tickers.slice(0); - for(var i = 0, len = tickersCopy.length; i < len; i++){ - tickersCopy[i].tick(deltaTime); - } - }, - - /** - * @language=en - * Get the fps. - */ - getMeasuredFPS: function(){ - return Math.min(this._measuredFPS, this._targetFPS); - }, - - /** - * @language=en - * Add tickObject. The tickObject must implement the tick method. - * @param {Object} tickObject The tickObject to add.It must implement the tick method. - */ - addTick: function(tickObject){ - if(!tickObject || typeof(tickObject.tick) != 'function'){ - throw new Error('Ticker: The tick object must implement the tick method.'); - } - this._tickers.push(tickObject); - }, - - /** - * @language=en - * Remove the tickObject - * @param {Object} tickObject The tickObject to remove. - */ - removeTick: function(tickObject){ - var tickers = this._tickers, - index = tickers.indexOf(tickObject); - if(index >= 0){ - tickers.splice(index, 1); - } - }, - /** - * 下次tick时回调 - * @param {Function} callback - * @return {tickObj} - */ - nextTick:function(callback){ - var that = this; - var tickObj = { - tick:function(dt){ - that.removeTick(tickObj); - callback(); - } - }; - - that.addTick(tickObj); - return tickObj; - }, - /** - * 延迟指定的时间后调用回调, 类似setTimeout - * @param {Function} callback - * @param {Number} duration 延迟的毫秒数 - * @return {tickObj} - */ - timeout:function(callback, duration){ - var that = this; - var targetTime = new Date().getTime() + duration; - var tickObj = { - tick:function(){ - var nowTime = new Date().getTime(); - var dt = nowTime - targetTime; - if(dt >= 0){ - that.removeTick(tickObj); - callback(); - } - } - }; - that.addTick(tickObj); - return tickObj; - }, - /** - * 指定的时间周期来调用函数, 类似setInterval - * @param {Function} callback - * @param {Number} duration 时间周期,单位毫秒 - * @return {tickObj} - */ - interval:function(callback, duration){ - var that = this; - var targetTime = new Date().getTime() + duration; - var tickObj = { - tick:function(){ - var nowTime = new Date().getTime(); - var dt = nowTime - targetTime; - if(dt >= 0){ - if(dt < duration){ - nowTime -= dt; - } - targetTime = nowTime + duration; - callback(); - } - } - }; - that.addTick(tickObj); - return tickObj; - } -}); -window.Hilo.Ticker = Ticker; -})(window); \ No newline at end of file +!function(t){t.Hilo||(t.Hilo={});var i=t.Hilo.Class,e=t.Hilo.browser,n=i.create({constructor:function(t){this._targetFPS=t||60,this._interval=1e3/this._targetFPS,this._tickers=[]},_paused:!1,_targetFPS:0,_interval:0,_intervalId:null,_tickers:null,_lastTime:0,_tickCount:0,_tickTime:0,_measuredFPS:0,start:function(i){if(void 0===i&&(i=!0),!this._intervalId){this._lastTime=+new Date;var n,s=this,a=this._interval,r=t.requestAnimationFrame||t[e.jsVendor+"RequestAnimationFrame"];i&&r&&a<17?(this._useRAF=!0,n=function(){s._intervalId=r(n),s._tick()}):n=function(){s._intervalId=setTimeout(n,a),s._tick()},this._paused=!1,n()}},stop:function(){if(this._useRAF){var i=t.cancelAnimationFrame||t[e.jsVendor+"CancelAnimationFrame"];i(this._intervalId)}else clearTimeout(this._intervalId);this._intervalId=null,this._lastTime=0,this._paused=!0},pause:function(){this._paused=!0},resume:function(){this._paused=!1},_tick:function(){if(!this._paused){var t=+new Date,i=t-this._lastTime,e=this._tickers;++this._tickCount>=this._targetFPS?(this._measuredFPS=1e3/(this._tickTime/this._tickCount)+.5>>0,this._tickCount=0,this._tickTime=0):this._tickTime+=t-this._lastTime,this._lastTime=t;for(var n=e.slice(0),s=0,a=n.length;s=0&&i.splice(e,1)},nextTick:function(t){var i=this,e={tick:function(n){i.removeTick(e),t()}};return i.addTick(e),e},timeout:function(t,i){var e=this,n=(new Date).getTime()+i,s={tick:function(){var i=(new Date).getTime(),a=i-n;a>=0&&(e.removeTick(s),t())}};return e.addTick(s),s},interval:function(t,i){var e=this,n=(new Date).getTime()+i,s={tick:function(){var e=(new Date).getTime(),s=e-n;s>=0&&(s - *
    - * example: - *
    - * var bmp = new Bitmap({image:img});
    - * Hilo.util.copy(bmp, Hilo.drag);
    - * bmp.startDrag([0, 0, 550, 400]);
    - * 
    - * @class drag A mixin that contains drag method.You can mix drag method to the visual target by use Class.mix(target, drag) or Hilo.util.copy(target, drag). - * @mixin - * @static - * @module hilo/util/drag - * @requires hilo/core/Hilo - */ -var drag = { - _isDragStart:false, - /** - * 是否需要 transform,父元素有 transform 时需要设置为true - * @default false - * @type {Boolean} - */ - dragNeedTransform:false, - /** - * @language=en - * start drag. - * @param {Array} bounds The bounds area that the view can move, relative to the coordinates of the view's parent, [x, y, width, height], default is no limit. - */ - startDrag:function(bounds){ - var that = this; - - if(that._isDragStart){ - that.stopDrag(); - } - that._isDragStart = true; - - var stage; - bounds = bounds||[-Infinity, -Infinity, Infinity, Infinity]; - var mouse = { - x:0, - y:0, - preX:0, - preY:0 - }; - var minX = bounds[0]; - var minY = bounds[1]; - var maxX = bounds[2] == Infinity?Infinity:minX + bounds[2]; - var maxY = bounds[3] == Infinity?Infinity:minY + bounds[3]; - - var worldPoint = { - x:0, - y:0 - }; - - function onStart(e){ - e.stopPropagation(); - updateMouse(e); - that.off(Hilo.event.POINTER_START, onStart); - - worldPoint.x = that.x; - worldPoint.y = that.y; - - if(that.dragNeedTransform && that.parent){ - that.parent.getConcatenatedMatrix().transformPoint(worldPoint); - } - - that.__dragX = worldPoint.x - mouse.x; - that.__dragY = worldPoint.y - mouse.y; - - if(!stage){ - stage = that.getStage(); - } - stage.on(Hilo.event.POINTER_MOVE, onMove); - document.addEventListener(Hilo.event.POINTER_END, onStop); - that.fire("dragStart", mouse); - } - - function onStop(e){ - document.removeEventListener(Hilo.event.POINTER_END, onStop); - stage && stage.off(Hilo.event.POINTER_MOVE, onMove); - - that.on(Hilo.event.POINTER_START, onStart); - that.fire("dragEnd", mouse); - } - - function onMove(e){ - updateMouse(e); - - worldPoint.x = mouse.x + that.__dragX; - worldPoint.y = mouse.y + that.__dragY; - - if(that.dragNeedTransform && that.parent){ - that.parent.getConcatenatedMatrix().invert().transformPoint(worldPoint); - } - - that.x = Math.max(minX, Math.min(maxX, worldPoint.x)); - that.y = Math.max(minY, Math.min(maxY, worldPoint.y)); - that.fire("dragMove", mouse); - } - - function updateMouse(e){ - mouse.preX = mouse.x; - mouse.preY = mouse.y; - mouse.x = e.stageX; - mouse.y = e.stageY; - } - - function stopDrag(){ - that._isDragStart = false; - document.removeEventListener(Hilo.event.POINTER_END, onStop); - stage && stage.off(Hilo.event.POINTER_MOVE, onMove); - that.off(Hilo.event.POINTER_START, onStart); - } - that.on(Hilo.event.POINTER_START, onStart); - - that.stopDrag = stopDrag; - }, - /** - * @language=en - * stop drag. - */ - stopDrag:function(){ - this._isDragStart = false; - } -}; -window.Hilo.drag = drag; -})(window); \ No newline at end of file +!function(t){t.Hilo||(t.Hilo={});var e=t.Hilo,r={_isDragStart:!1,dragNeedTransform:!1,startDrag:function(t){function r(t){t.stopPropagation(),o(t),g.off(e.event.POINTER_START,r),E.x=g.x,E.y=g.y,g.dragNeedTransform&&g.parent&&g.parent.getConcatenatedMatrix().transformPoint(E),g.__dragX=E.x-d.x,g.__dragY=E.y-d.y,f||(f=g.getStage()),f.on(e.event.POINTER_MOVE,a),document.addEventListener(e.event.POINTER_END,n),g.fire("dragStart",d)}function n(t){document.removeEventListener(e.event.POINTER_END,n),f&&f.off(e.event.POINTER_MOVE,a),g.on(e.event.POINTER_START,r),g.fire("dragEnd",d)}function a(t){o(t),E.x=d.x+g.__dragX,E.y=d.y+g.__dragY,g.dragNeedTransform&&g.parent&&g.parent.getConcatenatedMatrix().invert().transformPoint(E),g.x=Math.max(_,Math.min(v,E.x)),g.y=Math.max(s,Math.min(T,E.y)),g.fire("dragMove",d)}function o(t){d.preX=d.x,d.preY=d.y,d.x=t.stageX,d.y=t.stageY}function i(){g._isDragStart=!1,document.removeEventListener(e.event.POINTER_END,n),f&&f.off(e.event.POINTER_MOVE,a),g.off(e.event.POINTER_START,r)}var g=this;g._isDragStart&&g.stopDrag(),g._isDragStart=!0;var f;t=t||[-(1/0),-(1/0),1/0,1/0];var d={x:0,y:0,preX:0,preY:0},_=t[0],s=t[1],v=t[2]==1/0?1/0:_+t[2],T=t[3]==1/0?1/0:s+t[3],E={x:0,y:0};g.on(e.event.POINTER_START,r),g.stopDrag=i},stopDrag:function(){this._isDragStart=!1}};t.Hilo.drag=r}(window); \ No newline at end of file diff --git a/build/standalone/hilo/util/polyfill.js b/build/standalone/hilo/util/polyfill.js index 5a43a7d8..5f6ad103 100644 --- a/build/standalone/hilo/util/polyfill.js +++ b/build/standalone/hilo/util/polyfill.js @@ -1,5 +1,5 @@ /** - * Hilo 1.5.0 for standalone + * Hilo 1.6.0 for standalone * Copyright 2016 alibaba.com * Licensed under the MIT License */ diff --git a/build/standalone/hilo/util/polyfill.min.js b/build/standalone/hilo/util/polyfill.min.js index 027135b3..73c2029d 100644 --- a/build/standalone/hilo/util/polyfill.min.js +++ b/build/standalone/hilo/util/polyfill.min.js @@ -1,53 +1,6 @@ /** - * Hilo 1.5.0 for standalone + * Hilo 1.6.0 for standalone * Copyright 2016 alibaba.com * Licensed under the MIT License */ -/** - * Hilo 1.5.0 for standalone - * Copyright 2016 alibaba.com - * Licensed under the MIT License - */ -(function(window){ -if(!window.Hilo) window.Hilo = {}; - - -var arrayProto = Array.prototype, - slice = arrayProto.slice; - -//polyfiil for Array.prototype.indexOf -if (!arrayProto.indexOf) { - arrayProto.indexOf = function(elem, fromIndex){ - fromIndex = fromIndex || 0; - var len = this.length, i; - if(len == 0 || fromIndex >= len) return -1; - if(fromIndex < 0) fromIndex = len + fromIndex; - for(i = fromIndex; i < len; i++){ - if(this[i] === elem) return i; - } - return -1; - }; -} - -var fnProto = Function.prototype; - -//polyfill for Function.prototype.bind -if (!fnProto.bind) { - fnProto.bind = function(thisArg){ - var target = this, - boundArgs = slice.call(arguments, 1), - F = function(){}; - - function bound(){ - var args = boundArgs.concat(slice.call(arguments)); - return target.apply(this instanceof bound ? this : thisArg, args); - } - - F.prototype = target.prototype; - bound.prototype = new F(); - - return bound; - }; -} -window.Hilo.undefined = undefined; -})(window); \ No newline at end of file +!function(n){n.Hilo||(n.Hilo={});var t=Array.prototype,i=t.slice;t.indexOf||(t.indexOf=function(n,t){t=t||0;var i,o=this.length;if(0==o||t>=o)return-1;for(t<0&&(t=o+t),i=t;i - *
    - * Example: - *
    - * var bmp = new Hilo.Bitmap({image:imgElem, rect:[0, 0, 100, 100]});
    - * stage.addChild(bmp);
    - * 
    - * @class Bitmap - * @augments View - * @param {Object} properties the options of create Instance.It can contains all writable property and Moreover: - *
      - *
    • image - the image of bitmap which contained, required.
    • - *
    • rect - the range of bitmap in the image, option
    • - *
    • crossOrigin - Whether cross-domain is needed, default is false
    • - *
    - * @module hilo/view/Bitmap - * @requires hilo/core/Hilo - * @requires hilo/core/Class - * @requires hilo/view/View - * @requires hilo/view/Drawable - */ - var Bitmap = Class.create(/** @lends Bitmap.prototype */{ - Extends: View, - constructor: function(properties){ - properties = properties || {}; - this.id = this.id || properties.id || Hilo.getUid("Bitmap"); - Bitmap.superclass.constructor.call(this, properties); - - this.drawable = new Drawable(properties); - - //init width and height - if(!this.width || !this.height){ - var rect = this.drawable.rect; - if(rect){ - this.width = rect[2]; - this.height = rect[3]; - } - } - }, - - /** - * @language=en - * set the image。 - * @param {Image|String} Image Object or URL. - * @param {Array} rect the range of bitmap in the image, option. - * @param {Boolean} Whether cross-domain is needed, default is false. - * @returns {Bitmap} self。 - */ - setImage: function(image, rect, crossOrigin){ - this.drawable.init({image:image, rect:rect, crossOrigin:crossOrigin}); - if(rect){ - this.width = rect[2]; - this.height = rect[3]; - } - else if(!this.width && !this.height){ - rect = this.drawable.rect; - if(rect){ - this.width = rect[2]; - this.height = rect[3]; - } - } - return this; - } - }); - -window.Hilo.Bitmap = Bitmap; -})(window); \ No newline at end of file +!function(i){i.Hilo||(i.Hilo={});var t=i.Hilo,h=i.Hilo.Class,s=i.Hilo.View,e=i.Hilo.Drawable,a=h.create({Extends:s,constructor:function(i){if(i=i||{},this.id=this.id||i.id||t.getUid("Bitmap"),a.superclass.constructor.call(this,i),this.drawable=new e(i),!this.width||!this.height){var h=this.drawable.rect;h&&(this.width=h[2],this.height=h[3])}},setImage:function(i,t,h){return this.drawable.init({image:i,rect:t,crossOrigin:h}),t?(this.width=t[2],this.height=t[3]):this.width||this.height||(t=this.drawable.rect,t&&(this.width=t[2],this.height=t[3])),this}});i.Hilo.Bitmap=a}(window); \ No newline at end of file diff --git a/build/standalone/hilo/view/BitmapText.js b/build/standalone/hilo/view/BitmapText.js index 0dbace01..c1483aa1 100644 --- a/build/standalone/hilo/view/BitmapText.js +++ b/build/standalone/hilo/view/BitmapText.js @@ -1,5 +1,5 @@ /** - * Hilo 1.5.0 for standalone + * Hilo 1.6.0 for standalone * Copyright 2016 alibaba.com * Licensed under the MIT License */ diff --git a/build/standalone/hilo/view/BitmapText.min.js b/build/standalone/hilo/view/BitmapText.min.js index 39d51a3f..2991d531 100644 --- a/build/standalone/hilo/view/BitmapText.min.js +++ b/build/standalone/hilo/view/BitmapText.min.js @@ -1,190 +1,6 @@ /** - * Hilo 1.5.0 for standalone + * Hilo 1.6.0 for standalone * Copyright 2016 alibaba.com * Licensed under the MIT License */ -/** - * Hilo 1.5.0 for standalone - * Copyright 2016 alibaba.com - * Licensed under the MIT License - */ -(function(window){ -if(!window.Hilo) window.Hilo = {}; -var Class = window.Hilo.Class; -var Hilo = window.Hilo;var Container = window.Hilo.Container; -var Bitmap = window.Hilo.Bitmap; - - -/** - * @language=en - * - *
    - * @class BitmapText support bitmap text function ,but only support single-line text - * @augments Container - * @param {Object} properties the options of create Instance.It can contains all writable property - * @module hilo/view/BitmapText - * @requires hilo/core/Class - * @requires hilo/core/Hilo - * @requires hilo/view/Container - * @requires hilo/view/Bitmap - * @property {Object} glyphs font glyph set of bitmap. format:{letter:{image:img, rect:[0,0,100,100]}} - * @property {Number} letterSpacing spacing of letter. default:0 - * @property {String} text content of bitmap text. Not writable,set this value by 'setText' - * @property {String} textAlign property values:left、center、right, default:left,Not writable,set this property by 'setTextAlign' - */ -var BitmapText = Class.create(/** @lends BitmapText.prototype */{ - Extends: Container, - constructor: function(properties){ - properties = properties || {}; - this.id = this.id || properties.id || Hilo.getUid('BitmapText'); - BitmapText.superclass.constructor.call(this, properties); - - var text = properties.text + ''; - if(text){ - this.text = ''; - this.setText(text); - } - - this.pointerChildren = false; //disable user events for single letters - }, - - glyphs: null, - letterSpacing: 0, - text: '', - textAlign:'left', - - /** - * @language=en - * set the content of bitmap text - * @param {String} text content - * @returns {BitmapText} BitmapText Instance,support chained calls - */ - setText: function(text){ - var me = this, str = text.toString(), len = str.length; - if(me.text == str) return; - me.text = str; - - var i, charStr, charGlyph, charObj, width = 0, height = 0, left = 0; - for(i = 0; i < len; i++){ - charStr = str.charAt(i); - charGlyph = me.glyphs[charStr]; - if(charGlyph){ - left = width + (width > 0 ? me.letterSpacing : 0); - if(me.children[i]){ - charObj = me.children[i]; - charObj.setImage(charGlyph.image, charGlyph.rect); - } - else{ - charObj = me._createBitmap(charGlyph); - me.addChild(charObj); - } - charObj.x = left; - width = left + charGlyph.rect[2]; - height = Math.max(height, charGlyph.rect[3]); - } - } - - for(i = me.children.length - 1;i >= len;i --){ - me._releaseBitmap(me.children[i]); - me.children[i].removeFromParent(); - } - - me.width = width; - me.height = height; - this.setTextAlign(); - return me; - }, - _createBitmap:function(cfg){ - var bmp; - if(BitmapText._pool.length){ - bmp = BitmapText._pool.pop(); - bmp.setImage(cfg.image, cfg.rect); - } - else{ - bmp = new Bitmap({ - image:cfg.image, - rect:cfg.rect - }); - } - return bmp; - }, - _releaseBitmap:function(bmp){ - BitmapText._pool.push(bmp); - }, - - /** - * @language=en - * set the textAlign of text。 - * @param textAlign value of textAlign:left、center、right - * @returns {BitmapText} itmapText Instance,support chained calls - */ - setTextAlign:function(textAlign){ - this.textAlign = textAlign||this.textAlign; - switch(this.textAlign){ - case "center": - this.pivotX = this.width * .5; - break; - case "right": - this.pivotX = this.width; - break; - case "left": - /* falls through */ - default: - this.pivotX = 0; - break; - } - return this; - }, - - /** - * @language=en - * detect whether can display the string by the currently assigned font provided - * @param {String} str to detect string - * @returns {Boolean} whether can display the string - */ - hasGlyphs: function(str){ - var glyphs = this.glyphs; - if(!glyphs) return false; - - str = str.toString(); - var len = str.length, i; - for(i = 0; i < len; i++){ - if(!glyphs[str.charAt(i)]) return false; - } - return true; - }, - - Statics:/** @lends BitmapText */{ - _pool:[], - /** - * @language=en - * easy way to generate a collection of glyphs - * @static - * @param {String} text character text. - * @param {Image} image character image. - * @param {Number} col default:the length of string - * @param {Number} row default:1 - * @returns {BitmapText} BitmapText对象本身。链式调用支持。 - */ - createGlyphs:function(text, image, col, row){ - var str = text.toString(); - col = col||str.length; - row = row||1; - var w = image.width/col; - var h = image.height/row; - var glyphs = {}; - for(var i = 0, l = text.length;i < l;i ++){ - var charStr = str.charAt(i); - glyphs[charStr] = { - image:image, - rect:[w * (i % col), h * Math.floor(i / col), w, h] - }; - } - return glyphs; - } - } - -}); - -window.Hilo.BitmapText = BitmapText; -})(window); \ No newline at end of file +!function(t){t.Hilo||(t.Hilo={});var e=t.Hilo.Class,i=t.Hilo,r=t.Hilo.Container,n=t.Hilo.Bitmap,h=e.create({Extends:r,constructor:function(t){t=t||{},this.id=this.id||t.id||i.getUid("BitmapText"),h.superclass.constructor.call(this,t);var e=t.text+"";e&&(this.text="",this.setText(e)),this.pointerChildren=!1},glyphs:null,letterSpacing:0,text:"",textAlign:"left",setText:function(t){var e=this,i=t.toString(),r=i.length;if(e.text!=i){e.text=i;var n,h,a,l,s=0,o=0,c=0;for(n=0;n0?e.letterSpacing:0),e.children[n]?(l=e.children[n],l.setImage(a.image,a.rect)):(l=e._createBitmap(a),e.addChild(l)),l.x=c,s=c+a.rect[2],o=Math.max(o,a.rect[3]));for(n=e.children.length-1;n>=r;n--)e._releaseBitmap(e.children[n]),e.children[n].removeFromParent();return e.width=s,e.height=o,this.setTextAlign(),e}},_createBitmap:function(t){var e;return h._pool.length?(e=h._pool.pop(),e.setImage(t.image,t.rect)):e=new n({image:t.image,rect:t.rect}),e},_releaseBitmap:function(t){h._pool.push(t)},setTextAlign:function(t){switch(this.textAlign=t||this.textAlign,this.textAlign){case"center":this.pivotX=.5*this.width;break;case"right":this.pivotX=this.width;break;case"left":default:this.pivotX=0}return this},hasGlyphs:function(t){var e=this.glyphs;if(!e)return!1;t=t.toString();var i,r=t.length;for(i=0;i - *
    - * demo: - *
    - * var btn = new Hilo.Button({
    - *     image: buttonImage,
    - *     upState: {rect:[0, 0, 64, 64]},
    - *     overState: {rect:[64, 0, 64, 64]},
    - *     downState: {rect:[128, 0, 64, 64]},
    - *     disabledState: {rect:[192, 0, 64, 64]}
    - * });
    - * 
    - * @class Button class is a simple button class, contains four kinds of state: 'up', 'over', 'down', 'disabled' - * @augments View - * @param {Object} properties create object properties. Contains all writable properties. Also contains: - *
      - *
    • image - the image element that button image is in
    • - *
    - * @module hilo/view/Button - * @requires hilo/core/Hilo - * @requires hilo/core/Class - * @requires hilo/view/View - * @requires hilo/view/Drawable - * @requires hilo/util/util - * @property {Object} upState The property of button 'up' state or collections of its drawable properties. - * @property {Object} overState The property of button 'over' state or collections of its drawable properties. - * @property {Object} downState The property of button 'down' state or collections of its drawable properties. - * @property {Object} disabledState The property of button 'disabled' state or collections of its drawable properties. - * @property {String} state the state name of button, could be one of Button.UP|OVER|DOWN|DISABLED, readonly! - * @property {Boolean} enabled Is button enabled. default value is true, readonly! - * @property {Boolean} useHandCursor If true, cursor over the button will become a pointer cursor, default value is true. - */ - var Button = Class.create(/** @lends Button.prototype */{ - Extends: View, - constructor: function(properties){ - properties = properties || {}; - this.id = this.id || properties.id || Hilo.getUid("Button"); - Button.superclass.constructor.call(this, properties); - - this.drawable = new Drawable(properties); - this.setState(Button.UP); - }, - - upState: null, - overState: null, - downState: null, - disabledState: null, - - state: null, - enabled: true, - useHandCursor: true, - - /** - * @language=en - * Set whether the button is enabled. - * @param {Boolean} enabled Show whether the button is enabled. - * @returns {Button} Return the button itself. - */ - setEnabled: function(enabled){ - if(this.enabled != enabled){ - if(!enabled){ - this.setState(Button.DISABLED); - }else{ - this.setState(Button.UP); - } - } - return this; - }, - - /** - * @language=en - * Set the state of the button. Invoke inside the Button and may not be used. - * @param {String} state New state of the button. - * @returns {Button} Return the button itself. - */ - setState: function(state){ - if(this.state !== state){ - this.state = state; - this.pointerEnabled = this.enabled = state !== Button.DISABLED; - - var stateObj; - switch(state){ - case Button.UP: - stateObj = this.upState; - break; - case Button.OVER: - stateObj = this.overState; - break; - case Button.DOWN: - stateObj = this.downState; - break; - case Button.DISABLED: - stateObj = this.disabledState; - break; - } - - if(stateObj){ - this.drawable.init(stateObj); - util.copy(this, stateObj, true); - } - } - - return this; - }, - - /** - * @language=en - * overwrite - * @private - */ - fire: function(type, detail){ - if(!this.enabled) return; - - var evtType = typeof type === 'string' ? type : type.type; - switch(evtType){ - case 'mousedown': - case 'touchstart': - case 'touchmove': - this.setState(Button.DOWN); - break; - case "mouseover": - this.setState(Button.OVER); - break; - case 'mouseup': - if(this.overState) this.setState(Button.OVER); - else if(this.upState) this.setState(Button.UP); - break; - case 'touchend': - case 'touchout': - case 'mouseout': - this.setState(Button.UP); - break; - } - - return Button.superclass.fire.call(this, type, detail); - }, - - Statics: /** @lends Button */ { - /** - * @language=en - * Statics value of Button's 'up' state. - * @type String - */ - UP: 'up', - /** - * @language=en - * Statics value of Button's 'over' state. - * @type String - */ - OVER: 'over', - /** - * @language=en - * Statics value of Button's 'down' state. - * @type String - */ - DOWN: 'down', - /** - * @language=en - * Statics value of Button's 'disabled' state. - * @type String - */ - DISABLED: 'disabled' - } - }); -window.Hilo.Button = Button; -})(window); \ No newline at end of file +!function(t){t.Hilo||(t.Hilo={});var e=t.Hilo,s=t.Hilo.Class,a=t.Hilo.View,i=t.Hilo.Drawable,o=t.Hilo.util,n=s.create({Extends:a,constructor:function(t){t=t||{},this.id=this.id||t.id||e.getUid("Button"),n.superclass.constructor.call(this,t),this.drawable=new i(t),this.setState(n.UP)},upState:null,overState:null,downState:null,disabledState:null,state:null,enabled:!0,useHandCursor:!0,setEnabled:function(t){return this.enabled!=t&&(t?this.setState(n.UP):this.setState(n.DISABLED)),this},setState:function(t){if(this.state!==t){this.state=t,this.pointerEnabled=this.enabled=t!==n.DISABLED;var e;switch(t){case n.UP:e=this.upState;break;case n.OVER:e=this.overState;break;case n.DOWN:e=this.downState;break;case n.DISABLED:e=this.disabledState}e&&(this.drawable.init(e),o.copy(this,e,!0))}return this},fire:function(t,e){if(this.enabled){var s="string"==typeof t?t:t.type;switch(s){case"mousedown":case"touchstart":case"touchmove":this.setState(n.DOWN);break;case"mouseover":this.setState(n.OVER);break;case"mouseup":this.overState?this.setState(n.OVER):this.upState&&this.setState(n.UP);break;case"touchend":case"touchout":case"mouseout":this.setState(n.UP)}return n.superclass.fire.call(this,t,e)}},Statics:{UP:"up",OVER:"over",DOWN:"down",DISABLED:"disabled"}});t.Hilo.Button=n}(window); \ No newline at end of file diff --git a/build/standalone/hilo/view/CacheMixin.js b/build/standalone/hilo/view/CacheMixin.js index 52d495e2..b0e38e85 100644 --- a/build/standalone/hilo/view/CacheMixin.js +++ b/build/standalone/hilo/view/CacheMixin.js @@ -1,5 +1,5 @@ /** - * Hilo 1.5.0 for standalone + * Hilo 1.6.0 for standalone * Copyright 2016 alibaba.com * Licensed under the MIT License */ diff --git a/build/standalone/hilo/view/CacheMixin.min.js b/build/standalone/hilo/view/CacheMixin.min.js index 57a20cee..89d1a266 100644 --- a/build/standalone/hilo/view/CacheMixin.min.js +++ b/build/standalone/hilo/view/CacheMixin.min.js @@ -1,71 +1,6 @@ /** - * Hilo 1.5.0 for standalone + * Hilo 1.6.0 for standalone * Copyright 2016 alibaba.com * Licensed under the MIT License */ -/** - * Hilo 1.5.0 for standalone - * Copyright 2016 alibaba.com - * Licensed under the MIT License - */ -(function(window){ -if(!window.Hilo) window.Hilo = {}; -var Drawable = window.Hilo.Drawable; -var browser = window.Hilo.browser; - - -var _cacheCanvas, _cacheContext; -/** - * @language=en - * @class CacheMixin A mixin that contains cache method.You can mix cache method to the target by use Class.mix(target, CacheMixin). - * @static - * @mixin - * @module hilo/view/CacheMixin - * @requires hilo/view/Drawable - * @requires hilo/util/browser - */ -var CacheMixin = /** @lends CacheMixin# */ { - _cacheDirty:true, - /** - * @language=en - * Cache the view. - * @param {Boolean} forceUpdate is force update cache. - */ - cache: function(forceUpdate){ - if(forceUpdate || this._cacheDirty || !this.drawable){ - this.updateCache(); - } - }, - /** - * @language=en - * Update the cache. - */ - updateCache:function(){ - if(browser.supportCanvas){ - if(!_cacheCanvas){ - _cacheCanvas = document.createElement('canvas'); - _cacheContext = _cacheCanvas.getContext('2d'); - } - - //TODO:width, height自动判断 - _cacheCanvas.width = this.width; - _cacheCanvas.height = this.height; - this._draw(_cacheContext); - this.drawable = this.drawable||new Drawable(); - this.drawable.init({ - image:_cacheCanvas.toDataURL() - }); - this._cacheDirty = false; - } - }, - /** - * @language=en - * set the cache state diry. - * @param {Boolean} dirty is cache dirty - */ - setCacheDirty:function(dirty){ - this._cacheDirty = dirty; - } -}; -window.Hilo.CacheMixin = CacheMixin; -})(window); \ No newline at end of file +!function(t){t.Hilo||(t.Hilo={});var i,a,e=t.Hilo.Drawable,h=t.Hilo.browser,c={_cacheDirty:!0,cache:function(t){(t||this._cacheDirty||!this.drawable)&&this.updateCache()},updateCache:function(){h.supportCanvas&&(i||(i=document.createElement("canvas"),a=i.getContext("2d")),i.width=this.width,i.height=this.height,this._draw(a),this.drawable=this.drawable||new e,this.drawable.init({image:i.toDataURL()}),this._cacheDirty=!1)},setCacheDirty:function(t){this._cacheDirty=t}};t.Hilo.CacheMixin=c}(window); \ No newline at end of file diff --git a/build/standalone/hilo/view/Container.js b/build/standalone/hilo/view/Container.js index 32302834..fb6e0a80 100644 --- a/build/standalone/hilo/view/Container.js +++ b/build/standalone/hilo/view/Container.js @@ -1,5 +1,5 @@ /** - * Hilo 1.5.0 for standalone + * Hilo 1.6.0 for standalone * Copyright 2016 alibaba.com * Licensed under the MIT License */ diff --git a/build/standalone/hilo/view/Container.min.js b/build/standalone/hilo/view/Container.min.js index d3b2bf88..c92713e7 100644 --- a/build/standalone/hilo/view/Container.min.js +++ b/build/standalone/hilo/view/Container.min.js @@ -1,379 +1,6 @@ /** - * Hilo 1.5.0 for standalone + * Hilo 1.6.0 for standalone * Copyright 2016 alibaba.com * Licensed under the MIT License */ -/** - * Hilo 1.5.0 for standalone - * Copyright 2016 alibaba.com - * Licensed under the MIT License - */ -(function(window){ -if(!window.Hilo) window.Hilo = {}; -var Hilo = window.Hilo;var Class = window.Hilo.Class; -var View = window.Hilo.View; - - -/** - * @language=en - * @class Container is the base class to all container classes. Each Container can add other view object as children. - * @augments View - * @param {Object} properties Properties parameters of the object to create. Contains all writable properties of this class. - * @module hilo/view/Container - * @requires hilo/core/Hilo - * @requires hilo/core/Class - * @requires hilo/view/View - * @property {Array} children List of children elements of the container, readonly! - * @property {Boolean} pointerChildren Whether children elements of the container can response to user interactive events, default value is true. - * @property {Boolean} clipChildren Whether clip children elements which are out of the container, default value is false. - */ -var Container = Class.create(/** @lends Container.prototype */{ - Extends: View, - constructor: function(properties){ - properties = properties || {}; - this.id = this.id || properties.id || Hilo.getUid("Container"); - Container.superclass.constructor.call(this, properties); - - if(this.children) this._updateChildren(); - else this.children = []; - }, - - children: null, - pointerChildren: true, - clipChildren: false, - - /** - * @language=en - * Return the amount of the children elements of the container. - * @returns {Uint} The amount of the children elements of the container. - */ - getNumChildren: function(){ - return this.children.length; - }, - - /** - * @language=en - * Add child element at given index. - * @param {View} child Element to add. - * @param {Number} index The given index position, range from 0. - */ - addChildAt: function(child, index){ - var children = this.children, - len = children.length, - parent = child.parent; - - index = index < 0 ? 0 : index > len ? len : index; - var childIndex = this.getChildIndex(child); - if(childIndex == index){ - return this; - }else if(childIndex >= 0){ - children.splice(childIndex, 1); - index = index == len ? len - 1 : index; - }else if(parent){ - parent.removeChild(child); - } - - children.splice(index, 0, child); - - //直接插入,影响插入位置之后的深度 - //Insert directly, this will affect depth of elements after the index. - if(childIndex < 0){ - this._updateChildren(index); - } - //只是移动时影响中间段的深度 - //Will affect depth of elements in the middle during moving - else{ - var startIndex = childIndex < index ? childIndex : index; - var endIndex = childIndex < index ? index : childIndex; - this._updateChildren(startIndex, endIndex + 1); - } - - return this; - }, - - /** - * @language=en - * Add child element at the top. - * @param {View} child Elements to add. - */ - addChild: function(child){ - var total = this.children.length, - args = arguments; - - for(var i = 0, len = args.length; i < len; i++){ - this.addChildAt(args[i], total + i); - } - return this; - }, - - /** - * @language=en - * Remove element at the index. - * @param {Int} index Index of the element to remove, range from 0. - * @returns {View} Element had been removed. - */ - removeChildAt: function(index){ - var children = this.children; - if(index < 0 || index >= children.length) return null; - - var child = children[index]; - if(child){ - //NOTE: use `__renderer` for fixing child removal (DOMRenderer and FlashRenderer only). - //Do `not` use it in any other case. - if(!child.__renderer){ - var obj = child; - while(obj = obj.parent){ - //obj is stage - if(obj.renderer){ - child.__renderer = obj.renderer; - break; - } - else if(obj.__renderer){ - child.__renderer = obj.__renderer; - break; - } - } - } - - if(child.__renderer){ - child.__renderer.remove(child); - } - - child.parent = null; - child.depth = -1; - } - - children.splice(index, 1); - this._updateChildren(index); - - return child; - }, - - /** - * @language=en - * Remove the given child element. - * @param {View} child The child element to remove. - * @returns {View} Element had been removed. - */ - removeChild: function(child){ - return this.removeChildAt(this.getChildIndex(child)); - }, - - /** - * @language=en - * Remove child element by its id. - * @param {String} id The id of element to remove. - * @returns {View} Element had been removed. - */ - removeChildById: function(id){ - var children = this.children, child; - for(var i = 0, len = children.length; i < len; i++){ - child = children[i]; - if(child.id === id){ - this.removeChildAt(i); - return child; - } - } - return null; - }, - - /** - * @language=en - * Remove all children elements. - * @returns {Container} Container itself. - */ - removeAllChildren: function(){ - while(this.children.length) this.removeChildAt(0); - return this; - }, - - /** - * @language=en - * Return child element at the given index. - * @param {Number} index The index of the element, range from 0. - */ - getChildAt: function(index){ - var children = this.children; - if(index < 0 || index >= children.length) return null; - return children[index]; - }, - - /** - * @language=en - * Return child element at the given id. - * @param {String} id The id of child element to return. - */ - getChildById: function(id){ - var children = this.children, child; - for(var i = 0, len = children.length; i < len; i++){ - child = children[i]; - if(child.id === id) return child; - } - return null; - }, - - /** - * @language=en - * Return index value of the given child element. - * @param {View} child The child element need to get its index. - */ - getChildIndex: function(child){ - return this.children.indexOf(child); - }, - - /** - * @language=en - * Set the index of child element. - * @param {View} child The child element need to set index. - * @param {Number} index The index to set to the element. - */ - setChildIndex: function(child, index){ - var children = this.children, - oldIndex = children.indexOf(child); - - if(oldIndex >= 0 && oldIndex != index){ - var len = children.length; - index = index < 0 ? 0 : index >= len ? len - 1 : index; - children.splice(oldIndex, 1); - children.splice(index, 0, child); - this._updateChildren(); - } - return this; - }, - - /** - * @language=en - * Swap index between two child elements. - * @param {View} child1 Child element A. - * @param {View} child2 Child element B. - */ - swapChildren: function(child1, child2){ - var children = this.children, - index1 = this.getChildIndex(child1), - index2 = this.getChildIndex(child2); - - child1.depth = index2; - children[index2] = child1; - child2.depth = index1; - children[index1] = child2; - }, - - /** - * @language=en - * Swap two children elements at given indexes. - * @param {Number} index1 Given index A. - * @param {Number} index2 Given index B. - */ - swapChildrenAt: function(index1, index2){ - var children = this.children, - child1 = this.getChildAt(index1), - child2 = this.getChildAt(index2); - - child1.depth = index2; - children[index2] = child1; - child2.depth = index1; - children[index1] = child2; - }, - - /** - * @language=en - * Sort children elements by the given key or function. - * @param {Object} keyOrFunction If is String, sort children elements by the given property string; If is Function, sort by the function. - */ - sortChildren: function(keyOrFunction){ - var fn = keyOrFunction, - children = this.children; - if(typeof fn == "string"){ - var key = fn; - fn = function(a, b){ - return b[key] - a[key]; - }; - } - children.sort(fn); - this._updateChildren(); - }, - - /** - * @language=en - * Update children elements. - * @private - */ - _updateChildren: function(start, end){ - var children = this.children, child; - start = start || 0; - end = end || children.length; - for(var i = start; i < end; i++){ - child = children[i]; - child.depth = i + 1; - child.parent = this; - } - }, - - /** - * @language=en - * Return whether this container contains the parameter described child element. - * @param {View} child The child element to test. - */ - contains: function(child){ - while(child = child.parent){ - if(child === this){ - return true; - } - } - return false; - }, - - /** - * @language=en - * Return object at the point positioned by given values on x axis and y axis. - * @param {Number} x The point's value on the coordinate's x axis. - * @param {Number} y The point's value on the coordinate's y asix. - * @param {Boolean} usePolyCollision Whether use polygon collision detection, default value is false. - * @param {Boolean} global Whether return all elements that match the condition, default value is false. - * @param {Boolean} eventMode Whether find elements under event mode, default value is false. - */ - getViewAtPoint: function(x, y, usePolyCollision, global, eventMode){ - var result = global ? [] : null, - children = this.children, child, obj; - - for(var i = children.length - 1; i >= 0; i--){ - child = children[i]; - //skip child which is not shown or pointer enabled - if(!child || !child.visible || child.alpha <= 0 || (eventMode && !child.pointerEnabled)) continue; - //find child recursively - if(child.children && child.children.length && !(eventMode && !child.pointerChildren)){ - obj = child.getViewAtPoint(x, y, usePolyCollision, global, eventMode); - } - - if(obj){ - if(!global) return obj; - else if(obj.length) result = result.concat(obj); - }else if(child.hitTestPoint(x, y, usePolyCollision)){ - if(!global) return child; - else result.push(child); - } - } - - return global && result.length ? result : null; - }, - - /** - * @language=en - * Rewrite render method. - * @private - */ - render: function(renderer, delta){ - Container.superclass.render.call(this, renderer, delta); - - var children = this.children.slice(0), i, len, child; - for(i = 0, len = children.length; i < len; i++){ - child = children[i]; - //NOTE: the child could remove or change it's parent - if(child.parent === this) child._render(renderer, delta); - } - } - -}); - -window.Hilo.Container = Container; -})(window); \ No newline at end of file +!function(e){e.Hilo||(e.Hilo={});var i=e.Hilo,r=e.Hilo.Class,t=e.Hilo.View,n=r.create({Extends:t,constructor:function(e){e=e||{},this.id=this.id||e.id||i.getUid("Container"),n.superclass.constructor.call(this,e),this.children?this._updateChildren():this.children=[]},children:null,pointerChildren:!0,clipChildren:!1,getNumChildren:function(){return this.children.length},addChildAt:function(e,i){var r=this.children,t=r.length,n=e.parent;i=i<0?0:i>t?t:i;var h=this.getChildIndex(e);if(h==i)return this;if(h>=0?(r.splice(h,1),i=i==t?t-1:i):n&&n.removeChild(e),r.splice(i,0,e),h<0)this._updateChildren(i);else{var l=h=i.length)return null;var r=i[e];if(r){if(!r.__renderer)for(var t=r;t=t.parent;){if(t.renderer){r.__renderer=t.renderer;break}if(t.__renderer){r.__renderer=t.__renderer;break}}r.__renderer&&r.__renderer.remove(r),r.parent=null,r.depth=-1}return i.splice(e,1),this._updateChildren(e),r},removeChild:function(e){return this.removeChildAt(this.getChildIndex(e))},removeChildById:function(e){for(var i,r=this.children,t=0,n=r.length;t=i.length?null:i[e]},getChildById:function(e){for(var i,r=this.children,t=0,n=r.length;t=0&&t!=i){var n=r.length;i=i<0?0:i>=n?n-1:i,r.splice(t,1),r.splice(i,0,e),this._updateChildren()}return this},swapChildren:function(e,i){var r=this.children,t=this.getChildIndex(e),n=this.getChildIndex(i);e.depth=n,r[n]=e,i.depth=t,r[t]=i},swapChildrenAt:function(e,i){var r=this.children,t=this.getChildAt(e),n=this.getChildAt(i);t.depth=i,r[i]=t,n.depth=e,r[e]=n},sortChildren:function(e){var i=e,r=this.children;if("string"==typeof i){var t=i;i=function(e,i){return i[t]-e[t]}}r.sort(i),this._updateChildren()},_updateChildren:function(e,i){var r,t=this.children;e=e||0,i=i||t.length;for(var n=e;n=0;o--)if(h=s[o],!(!h||!h.visible||h.alpha<=0||n&&!h.pointerEnabled))if(h.children&&h.children.length&&(!n||h.pointerChildren)&&(l=h.getViewAtPoint(e,i,r,t,n)),l){if(!t)return l;l.length&&(d=d.concat(l))}else if(h.hitTestPoint(e,i,r)){if(!t)return h;d.push(h)}return t&&d.length?d:null},render:function(e,i){n.superclass.render.call(this,e,i);var r,t,h,l=this.children.slice(0);for(r=0,t=l.length;r - *
    - * demo: - *
    - * var domView = new Hilo.DOMElement({
    - *     element: Hilo.createElement('div', {
    - *         style: {
    - *             backgroundColor: '#004eff',
    - *             position: 'absolute'
    - *         }
    - *     }),
    - *     width: 100,
    - *     height: 100,
    - *     x: 50,
    - *     y: 70
    - * }).addTo(stage);
    - * 
    - * @name DOMElement - * @class DOMElement is a wrapper of dom element.(The DOMElement's parent must be stage) - * @augments View - * @param {Object} properties create Objects properties. Contains all writable properties in this class. Special properties include: - *
      - *
    • element - dom element to wrap, required!
    • - *
    - * @module hilo/view/DOMElement - * @requires hilo/core/Hilo - * @requires hilo/core/Class - * @requires hilo/view/View - * @requires hilo/view/Drawable - */ -var DOMElement = Class.create(/** @lends DOMElement.prototype */{ - Extends: View, - constructor: function(properties){ - properties = properties || {}; - this.id = this.id || properties.id || Hilo.getUid("DOMElement"); - DOMElement.superclass.constructor.call(this, properties); - - this.drawable = new Drawable(); - var elem = this.drawable.domElement = properties.element || Hilo.createElement('div'); - elem.id = this.id; - - if(this.pointerEnabled && !elem.style.pointerEvents){ - elem.style.pointerEvents = 'visible'; - } - }, - - /** - * @language=en - * Overwrite render method. - * @private - */ - _render: function(renderer, delta){ - if(!this.onUpdate || this.onUpdate(delta) !== false){ - renderer.transform(this); - if(this.visible && this.alpha > 0){ - this.render(renderer, delta); - } - } - }, - - /** - * @language=en - * Overwrite render method. - * @private - */ - render: function(renderer, delta){ - if(renderer.renderType !== 'dom'){ - var canvas = renderer.canvas; - var stage = this.parent; - var domElementContainer = renderer._domElementContainer; - if(!renderer._domElementContainer){ - domElementContainer = renderer._domElementContainer = Hilo.createElement('div', { - style:{ - 'position':'absolute', - 'transform':'scale3d(' + stage.scaleX + ',' + stage.scaleY + ', 1)', - 'transformOrigin':'0 0', - 'zIndex':'1' - } - }); - canvas.parentNode.insertBefore(renderer._domElementContainer, canvas.nextSibling); - } - - var elem = this.drawable.domElement, depth = this.depth, - nextElement = domElementContainer.childNodes[0], nextDepth; - if(elem.parentNode) return; - - //draw dom element just after stage canvas - while(nextElement && nextElement.nodeType != 3){ - nextDepth = parseInt(nextElement.style.zIndex) || 0; - if(nextDepth <= 0 || nextDepth > depth){ - break; - } - nextElement = nextElement.nextSibling; - } - domElementContainer.insertBefore(this.drawable.domElement, nextElement); - }else{ - renderer.draw(this); - } - } -}); -window.Hilo.DOMElement = DOMElement; -})(window); \ No newline at end of file +!function(e){e.Hilo||(e.Hilo={});var t=e.Hilo,n=e.Hilo.Class,i=e.Hilo.View,r=e.Hilo.Drawable,s=n.create({Extends:i,constructor:function(e){e=e||{},this.id=this.id||e.id||t.getUid("DOMElement"),s.superclass.constructor.call(this,e),this.drawable=new r;var n=this.drawable.domElement=e.element||t.createElement("div");n.id=this.id,this.pointerEnabled&&!n.style.pointerEvents&&(n.style.pointerEvents="visible")},_render:function(e,t){this.onUpdate&&this.onUpdate(t)===!1||(e.transform(this),this.visible&&this.alpha>0&&this.render(e,t))},render:function(e,n){if("dom"!==e.renderType){var i=e.canvas,r=this.parent,s=e._domElementContainer;e._domElementContainer||(s=e._domElementContainer=t.createElement("div",{style:{position:"absolute",transform:"scale3d("+r.scaleX+","+r.scaleY+", 1)",transformOrigin:"0 0",zIndex:"1"}}),i.parentNode.insertBefore(e._domElementContainer,i.nextSibling));var o,l=this.drawable.domElement,a=this.depth,d=s.childNodes[0];if(l.parentNode)return;for(;d&&3!=d.nodeType&&(o=parseInt(d.style.zIndex)||0,!(o<=0||o>a));)d=d.nextSibling;s.insertBefore(this.drawable.domElement,d)}else e.draw(this)}});e.Hilo.DOMElement=s}(window); \ No newline at end of file diff --git a/build/standalone/hilo/view/Drawable.js b/build/standalone/hilo/view/Drawable.js index 7426dbc0..fe5c645d 100644 --- a/build/standalone/hilo/view/Drawable.js +++ b/build/standalone/hilo/view/Drawable.js @@ -1,5 +1,5 @@ /** - * Hilo 1.5.0 for standalone + * Hilo 1.6.0 for standalone * Copyright 2016 alibaba.com * Licensed under the MIT License */ diff --git a/build/standalone/hilo/view/Drawable.min.js b/build/standalone/hilo/view/Drawable.min.js index 462b36da..ce4c94d8 100644 --- a/build/standalone/hilo/view/Drawable.min.js +++ b/build/standalone/hilo/view/Drawable.min.js @@ -1,86 +1,6 @@ /** - * Hilo 1.5.0 for standalone + * Hilo 1.6.0 for standalone * Copyright 2016 alibaba.com * Licensed under the MIT License */ -/** - * Hilo 1.5.0 for standalone - * Copyright 2016 alibaba.com - * Licensed under the MIT License - */ -(function(window){ -if(!window.Hilo) window.Hilo = {}; -var Class = window.Hilo.Class; -var util = window.Hilo.util; - - -/** - * @language=en - * @class Drawable is a wrapper of drawable images. - * @param {Object} properties create Objects properties, contains all writable properties. - * @module hilo/view/Drawable - * @requires hilo/core/Class - * @requires hilo/util/util - * @property {Object} image Image to be drawed, can used by CanvasRenderingContext2D.drawImage,like HTMLImageElement、HTMLCanvasElement、HTMLVideoElement。 - * @property {array} rect The retangle area that image will be drawed. - */ -var Drawable = Class.create(/** @lends Drawable.prototype */{ - constructor: function(properties){ - this.init(properties); - }, - - image: null, - rect: null, - - /** - * @language=en - * Initialize drawable elements. - * @param {Object} properties Properties need to be initialized. - */ - init: function(properties){ - var me = this, oldImage = me.image; - if(Drawable.isDrawable(properties)){ - me.image = properties; - }else{ - util.copy(me, properties, true); - } - - var image = me.image; - if(typeof image === 'string'){ - if(oldImage && image === oldImage.getAttribute('src')){ - image = me.image = oldImage; - }else{ - me.image = null; - //load image dynamically - var img = new Image(); - if(properties.crossOrigin){ - img.crossOrigin = "Anonymous"; - } - img.onload = function(){ - img.onload = null; - me.init(img); - }; - img.src = image; - return; - } - } - - if(image && !me.rect) me.rect = [0, 0, image.width, image.height]; - }, - - Statics: /** @lends Drawable */{ - /** - * @language=en - * Check whether the given 'elem' and be wrapped into Drawable object. - * @param {Object} elem Element to be tested. - * @return {Boolean} Return true if element can be wrapped into Drawable element, otherwises return false. - */ - isDrawable: function(elem){ - if(!elem || !elem.tagName) return false; - var tagName = elem.tagName.toLowerCase(); - return tagName === "img" || tagName === "canvas" || tagName === "video"; - } - } -}); -window.Hilo.Drawable = Drawable; -})(window); \ No newline at end of file +!function(i){i.Hilo||(i.Hilo={});var t=i.Hilo.Class,n=i.Hilo.util,a=t.create({constructor:function(i){this.init(i)},image:null,rect:null,init:function(i){var t=this,r=t.image;a.isDrawable(i)?t.image=i:n.copy(t,i,!0);var e=t.image;if("string"==typeof e){if(!r||e!==r.getAttribute("src")){t.image=null;var o=new Image;return i.crossOrigin&&(o.crossOrigin="Anonymous"),o.onload=function(){o.onload=null,t.init(o)},void(o.src=e)}e=t.image=r}e&&!t.rect&&(t.rect=[0,0,e.width,e.height])},Statics:{isDrawable:function(i){if(!i||!i.tagName)return!1;var t=i.tagName.toLowerCase();return"img"===t||"canvas"===t||"video"===t}}});i.Hilo.Drawable=a}(window); \ No newline at end of file diff --git a/build/standalone/hilo/view/Graphics.js b/build/standalone/hilo/view/Graphics.js index 958b3a60..2c8a2645 100644 --- a/build/standalone/hilo/view/Graphics.js +++ b/build/standalone/hilo/view/Graphics.js @@ -1,5 +1,5 @@ /** - * Hilo 1.5.0 for standalone + * Hilo 1.6.0 for standalone * Copyright 2016 alibaba.com * Licensed under the MIT License */ diff --git a/build/standalone/hilo/view/Graphics.min.js b/build/standalone/hilo/view/Graphics.min.js index 3647f618..effb2afb 100644 --- a/build/standalone/hilo/view/Graphics.min.js +++ b/build/standalone/hilo/view/Graphics.min.js @@ -1,568 +1,6 @@ /** - * Hilo 1.5.0 for standalone + * Hilo 1.6.0 for standalone * Copyright 2016 alibaba.com * Licensed under the MIT License */ -/** - * Hilo 1.5.0 for standalone - * Copyright 2016 alibaba.com - * Licensed under the MIT License - */ -(function(window){ -if(!window.Hilo) window.Hilo = {}; -var Hilo = window.Hilo;var Class = window.Hilo.Class; -var View = window.Hilo.View; -var CacheMixin = window.Hilo.CacheMixin; - - -/** - * @language=en - * - *
    - * @class Graphics class contains a group of functions for creating vector graphics. - * @augments View - * @mixes CacheMixin - * @borrows CacheMixin#cache as #cache - * @borrows CacheMixin#updateCache as #updateCache - * @borrows CacheMixin#setCacheDirty as #setCacheDirty - * @param {Object} properties Properties parameters of the object to create. Contains all writable properties of this class. - * @module hilo/view/Graphics - * @requires hilo/core/Hilo - * @requires hilo/core/Class - * @requires hilo/view/View - * @requires hilo/view/CacheMixin - * @property {Number} lineWidth The thickness of lines in space units, default value is 1, readonly! - * @property {Number} lineAlpha The alpha value (transparency) of line, default value is 1, readonly! - * @property {String} lineCap The style of how every end point of line are drawn, value options: butt, round, square. default value is null, readonly! - * @property {String} lineJoin The joint style of two lines. value options: miter, round, bevel. default value is null, readonly! - * @property {Number} miterLimit The miter limit ratio in space units, works only when lineJoin value is miter. default value is 10, readonly! - * @property {String} strokeStyle The color or style to use for lines around shapes, default value is 0 (the black color), readonly! - * @property {String} fillStyle The color or style to use inside shapes, default value is 0 (the black color), readonly! - * @property {Number} fillAlpha The transparency of color or style inside shapes, default value is 0, readonly! - */ -var Graphics = (function(){ - -var canvas = document.createElement('canvas'); -var helpContext = canvas.getContext && canvas.getContext('2d'); - -return Class.create(/** @lends Graphics.prototype */{ - Extends: View, - Mixes:CacheMixin, - constructor: function(properties){ - properties = properties || {}; - this.id = this.id || properties.id || Hilo.getUid('Graphics'); - Graphics.superclass.constructor.call(this, properties); - - this._actions = []; - }, - - lineWidth: 1, - lineAlpha: 1, - lineCap: null, //'butt', 'round', 'square' - lineJoin: null, //'miter', 'round', 'bevel' - miterLimit: 10, - hasStroke: false, - strokeStyle: '0', - hasFill: false, - fillStyle: '0', - fillAlpha: 0, - - /** - * @language=en - * Set the lines style for drawing shapes. - * @param {Number} thickness The thickness of lines, default value is 1. - * @param {String} lineColor The CSS color value of lines, default value is 0 (the black color). - * @param {Number} lineAlpha The transparency of lines, default value is 1 (fully opaque). - * @param {String} lineCap The style of how every end point of line are drawn, value options: butt, round, square. default value is null. - * @param {String} lineJoin The joint style of two lines. value options: miter, round, bevel. default value is null. - * @param {Number} miterLimit The miter limit ratio in space units, works only when lineJoin value is miter. default value is 10. - * @returns {Graphics} The Graphics Object. - */ - lineStyle: function(thickness, lineColor, lineAlpha, lineCap, lineJoin, miterLimit){ - var me = this, addAction = me._addAction; - - addAction.call(me, ['lineWidth', (me.lineWidth = thickness || 1)]); - addAction.call(me, ['strokeStyle', (me.strokeStyle = lineColor || '0')]); - addAction.call(me, ['lineAlpha', (me.lineAlpha = lineAlpha || 1)]); - if(lineCap != undefined) addAction.call(me, ['lineCap', (me.lineCap = lineCap)]); - if(lineJoin != undefined) addAction.call(me, ['lineJoin', (me.lineJoin = lineJoin)]); - if(miterLimit != undefined) addAction.call(me, ['miterLimit', (me.miterLimit = miterLimit)]); - me.hasStroke = true; - return me; - }, - - /** - * 设置虚线样式 - * @param {Number[]} segments 一组描述交替绘制线段和间距(坐标空间单位)长度的数字 - * @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/setLineDash - */ - setLineDash: function(segments){ - return this._addAction(['setLineDash', segments]); - }, - - /** - * @language=en - * Set how to fill shapes and the transparency. - * @param {String} fill Filling style. this can be color, gradient or pattern. - * @param {Number} alpha Transparency. - * @returns {Graphics} The Graphics Object. - */ - beginFill: function(fill, alpha){ - var me = this, addAction = me._addAction; - - addAction.call(me, ['fillStyle', (me.fillStyle = fill)]); - addAction.call(me, ['fillAlpha', (me.fillAlpha = alpha || 1)]); - me.hasFill = true; - return me; - }, - - /** - * @language=en - * Apply and end lines-drawing and shapes-filling. - * @returns {Graphics} The Graphics Object. - */ - endFill: function(){ - var me = this, addAction = me._addAction; - - if(me.hasStroke) addAction.call(me, ['stroke']); - if(me.hasFill) addAction.call(me, ['fill']); - me.setCacheDirty(true); - return me; - }, - - /** - * @language=en - * Set linear gradient filling style to draw shapes. - * @param {Number} x0 The x-coordinate value of the linear gradient start point. - * @param {Number} y0 The y-coordinate value of the linear gradient start point. - * @param {Number} x1 The x-coordinate value of the linear gradient end point. - * @param {Number} y1 The y-coordinate value of the linear gradient end point. - * @param {Array} colors An array of CSS colors used in the linear gradient. - * @param {Array} ratios An array of position between start point and end point, should be one-to-one to colors in the colors array. each value range between 0.0 to 1.0. - * @returns {Graphics} The Graphics Object. - */ - beginLinearGradientFill: function(x0, y0, x1, y1, colors, ratios){ - var me = this, gradient = helpContext.createLinearGradient(x0, y0, x1, y1); - - for (var i = 0, len = colors.length; i < len; i++){ - gradient.addColorStop(ratios[i], colors[i]); - } - me.hasFill = true; - return me._addAction(['fillStyle', (me.fillStyle = gradient)]); - }, - - /** - * @language=en - * Set radial gradient filling style to draw shapes. - * @param {Number} x0 The x-coordinate value of the radial gradient start circle. - * @param {Number} y0 The y-coordinate value of the radial gradient start circle. - * @param {Number} r0 The diameter of the radial gradient start circle. - * @param {Number} x1 The x-coordinate value of the radial gradient end circle. - * @param {Number} y1 The y-coordinate value of the radial gradient end circle. - * @param {Number} r1 The radius of the radial gradient end circle. - * @param {Array} colors An array of CSS colors used in the radial gradient. - * @param {Array} ratios An array of position between start circle and end circle, should be one-to-one to colors in the colors array. each value range between 0.0 to 1.0. - * @returns {Graphics} The Graphics Object. - */ - beginRadialGradientFill: function(x0, y0, r0, x1, y1, r1, colors, ratios){ - var me = this, gradient = helpContext.createRadialGradient(x0, y0, r0, x1, y1, r1); - for (var i = 0, len = colors.length; i < len; i++) - { - gradient.addColorStop(ratios[i], colors[i]); - } - me.hasFill = true; - return me._addAction(['fillStyle', (me.fillStyle = gradient)]); - }, - - /** - * @language=en - * Begin an image filling pattern. - * @param {HTMLImageElement} image The Image to fill. - * @param {String} repetition The fill repetition style, can be one of valus:repeat, repeat-x, repeat-y, no-repeat. default valus is ''. - * @returns {Graphics} The Graphics Object. - */ - beginBitmapFill: function(image, repetition){ - var me = this, pattern = helpContext.createPattern(image, repetition || ''); - me.hasFill = true; - return me._addAction(['fillStyle', (me.fillStyle = pattern)]); - }, - - /** - * @language=en - * Begin a new path. - * @returns {Graphics} The Graphics Object. - */ - beginPath: function(){ - return this._addAction(['beginPath']); - }, - - /** - * @language=en - * Close current path. - * @returns {Graphics} The Graphics Object. - */ - closePath: function(){ - return this._addAction(['closePath']); - }, - - /** - * @language=en - * Move current drawing point to a new point on coordinate values (x, y). - * @param {Number} x The x-coordinate value. - * @param {Number} y The y-coordinate value. - * @returns {Graphics} The Graphics Object. - */ - moveTo: function(x, y){ - return this._addAction(['moveTo', x, y]); - }, - - /** - * @language=en - * Draw a line from current point to the point on the coordinate value (x, y). - * @param {Number} x The x-coordinate value. - * @param {Number} y The y-coordinate value. - * @returns {Graphics} The Graphics Object. - */ - lineTo: function(x, y){ - return this._addAction(['lineTo', x, y]); - }, - - /** - * @language=en - * Draw a quadratic Bézier curve from current point to the point on coordinate (x, y). - * @param {Number} cpx The x-coordinate value of the Bézier curve control point cp. - * @param {Number} cpy The y-coordinate value of the Bézier curve control point cp. - * @param {Number} x The x-coordinate value. - * @param {Number} y The y-coordinate value. - * @returns {Graphics} The Graphics Object. - */ - quadraticCurveTo: function(cpx, cpy, x, y){ - return this._addAction(['quadraticCurveTo', cpx, cpy, x, y]); - }, - - /** - * @language=en - * Draw a Bézier curve from current point to the point on coordinate (x, y). - * @param {Number} cp1x The x-coordinate value of the Bézier curve control point cp1. - * @param {Number} cp1y The y-coordinate value of the Bézier curve control point cp1. - * @param {Number} cp2x The x-coordinate value of the Bézier curve control point cp2. - * @param {Number} cp2y The y-coordinate value of the Bézier curve control point cp2. - * @param {Number} x The x-coordinate value. - * @param {Number} y The y-coordinate value. - * @returns {Graphics} The Graphics Object. - */ - bezierCurveTo: function(cp1x, cp1y, cp2x, cp2y, x, y){ - return this._addAction(['bezierCurveTo', cp1x, cp1y, cp2x, cp2y, x, y]); - }, - - /** - * @language=en - * Draw a rectangle. - * @param {Number} x The x-coordinate value. - * @param {Number} y The y-coordinate value. - * @param {Number} width The width of the rectangle. - * @param {Number} height The height of the rectangle. - * @returns {Graphics} The Graphics Object. - */ - drawRect: function(x, y, width, height){ - return this._addAction(['rect', x, y, width, height]); - }, - - /** - * @language=en - * Draw a complex rounded rectangle. - * @param {Number} x The x-coordinate value. - * @param {Number} y The y-coordinate value. - * @param {Number} width The width of rounded rectangle. - * @param {Number} height The height of rounded rectangle. - * @param {Number} cornerTL The size of the rounded corner on the top-left of the rounded rectangle. - * @param {Number} cornerTR The size of the rounded corner on the top-right of the rounded rectangle. - * @param {Number} cornerBR The size of the rounded corner on the bottom-left of the rounded rectangle. - * @param {Number} cornerBL The size of the rounded corner on the bottom-right of the rounded rectangle. - * @returns {Graphics} The Graphics Object. - */ - drawRoundRectComplex: function(x, y, width, height, cornerTL, cornerTR, cornerBR, cornerBL){ - var me = this, addAction = me._addAction; - addAction.call(me, ['moveTo', x + cornerTL, y]); - addAction.call(me, ['lineTo', x + width - cornerTR, y]); - addAction.call(me, ['arc', x + width - cornerTR, y + cornerTR, cornerTR, -Math.PI/2, 0, false]); - addAction.call(me, ['lineTo', x + width, y + height - cornerBR]); - addAction.call(me, ['arc', x + width - cornerBR, y + height - cornerBR, cornerBR, 0, Math.PI/2, false]); - addAction.call(me, ['lineTo', x + cornerBL, y + height]); - addAction.call(me, ['arc', x + cornerBL, y + height - cornerBL, cornerBL, Math.PI/2, Math.PI, false]); - addAction.call(me, ['lineTo', x, y + cornerTL]); - addAction.call(me, ['arc', x + cornerTL, y + cornerTL, cornerTL, Math.PI, Math.PI*3/2, false]); - return me; - }, - - /** - * @language=en - * Draw a rounded rectangle. - * @param {Number} x The x-coordinate value. - * @param {Number} y The y-coordinate value. - * @param {Number} width The width of rounded rectangle. - * @param {Number} height The height of rounded rectangle. - * @param {Number} cornerSize The size of all rounded corners. - * @returns {Graphics} The Graphics Object. - */ - drawRoundRect: function(x, y, width, height, cornerSize){ - return this.drawRoundRectComplex(x, y, width, height, cornerSize, cornerSize, cornerSize, cornerSize); - }, - - /** - * @language=en - * Draw a circle. - * @param {Number} x The x-coordinate value. - * @param {Number} y The y-coordinate value. - * @param {Number} radius The radius of the circle. - * @returns {Graphics} The Graphics Object. - */ - drawCircle: function(x, y, radius){ - return this._addAction(['arc', x + radius, y + radius, radius, 0, Math.PI * 2, 0]); - }, - - /** - * @language=en - * Draw an ellipse. - * @param {Number} x The x-coordinate value. - * @param {Number} y The y-coordinate value. - * @param {Number} width The width of the ellipse. - * @param {Number} height The height of the ellipse. - * @returns {Graphics} The Graphics Object. - */ - drawEllipse: function(x, y, width, height){ - var me = this; - if(width == height) return me.drawCircle(x, y, width); - - var addAction = me._addAction; - var w = width / 2, h = height / 2, C = 0.5522847498307933, cx = C * w, cy = C * h; - x = x + w; - y = y + h; - - addAction.call(me, ['moveTo', x + w, y]); - addAction.call(me, ['bezierCurveTo', x + w, y - cy, x + cx, y - h, x, y - h]); - addAction.call(me, ['bezierCurveTo', x - cx, y - h, x - w, y - cy, x - w, y]); - addAction.call(me, ['bezierCurveTo', x - w, y + cy, x - cx, y + h, x, y + h]); - addAction.call(me, ['bezierCurveTo', x + cx, y + h, x + w, y + cy, x + w, y]); - return me; - }, - - /** - * @language=en - * Draw a path from the SVG data given by parameters. Not support Arcs. - * Demo: - *

    var path = 'M250 150 L150 350 L350 350 Z';

    - *

    var shape = new Hilo.Graphics({width:500, height:500});

    - *

    shape.drawSVGPath(path).beginFill('#0ff').endFill();

    - * @param {String} pathData The SVG path data to draw. - * @returns {Graphics} The Graphics Object. - */ - drawSVGPath: function(pathData){ - var me = this, addAction = me._addAction, - path = pathData.replace(/,/g, ' ').replace(/-/g, ' -').split(/(?=[a-zA-Z])/); - addAction.call(me, ['beginPath']); - var currentPoint = {x:0, y:0}; - var lastControlPoint = {x:0, y:0}; - var lastCmd; - for(var i = 0, len = path.length; i < len; i++){ - var str = path[i]; - if(!str.length){ - continue; - } - var realCmd = str[0]; - var cmd = realCmd.toUpperCase(); - var p = this._getSVGParams(str); - var useRelative = cmd !== realCmd; - - switch(cmd){ - case 'M': - if(useRelative){ - this._convertToAbsolute(currentPoint, p); - } - addAction.call(me, ['moveTo', p[0], p[1]]); - this._setCurrentPoint(currentPoint, p[0], p[1]); - break; - case 'L': - if(useRelative){ - this._convertToAbsolute(currentPoint, p); - } - addAction.call(me, ['lineTo', p[0], p[1]]); - this._setCurrentPoint(currentPoint, p[0], p[1]); - break; - case 'H': - if(useRelative){ - p[0] += currentPoint.x; - } - addAction.call(me, ['lineTo', p[0], currentPoint.y]); - currentPoint.x = p[0]; - break; - case 'V': - if(useRelative){ - p[0] += currentPoint.y; - } - addAction.call(me, ['lineTo', currentPoint.x, p[0]]); - currentPoint.y = p[0]; - break; - case 'Z': - addAction.call(me, ['closePath']); - break; - case 'C': - if(useRelative){ - this._convertToAbsolute(currentPoint, p); - } - addAction.call(me, ['bezierCurveTo', p[0], p[1], p[2], p[3], p[4], p[5]]); - lastControlPoint.x = p[2]; - lastControlPoint.y = p[3]; - this._setCurrentPoint(currentPoint, p[4], p[5]); - break; - case 'S': - if(useRelative){ - this._convertToAbsolute(currentPoint, p); - } - if(lastCmd === 'C' || lastCmd === 'S'){ - controlPoint = this._getReflectionPoint(currentPoint, lastControlPoint); - } - else{ - controlPoint = currentPoint; - } - addAction.call(me, ['bezierCurveTo', controlPoint.x, controlPoint.y, p[0], p[1], p[2], p[3]]); - lastControlPoint.x = p[0]; - lastControlPoint.y = p[1]; - this._setCurrentPoint(currentPoint, p[2], p[3]); - break; - case 'Q': - if(useRelative){ - this._convertToAbsolute(currentPoint, p); - } - addAction.call(me, ['quadraticCurveTo', p[0], p[1], p[2], p[3]]); - lastControlPoint.x = p[0]; - lastControlPoint.y = p[1]; - this._setCurrentPoint(currentPoint, p[2], p[3]); - break; - case 'T': - if(useRelative){ - this._convertToAbsolute(currentPoint, p); - } - var controlPoint; - if(lastCmd === 'Q' || lastCmd === 'T'){ - controlPoint = this._getReflectionPoint(currentPoint, lastControlPoint); - } - else{ - controlPoint = currentPoint; - } - addAction.call(me, ['quadraticCurveTo', controlPoint.x, controlPoint.y, p[0], p[1]]); - lastControlPoint = controlPoint; - this._setCurrentPoint(currentPoint, p[0], p[1]); - break; - } - lastCmd = cmd; - - } - return me; - }, - _getSVGParams:function(str){ - var p = str.substring(1).replace(/[\s]+$|^[\s]+/g, '').split(/[\s]+/); - if(p[0].length == 0) { - p.shift(); - } - for(var i = 0, l = p.length;i < l;i ++){ - p[i] = parseFloat(p[i]); - } - return p; - }, - _convertToAbsolute:function(currentPoint, data){ - for(var i = 0, l = data.length;i < l;i ++){ - if(i%2 === 0){ - data[i] += currentPoint.x; - } - else{ - data[i] += currentPoint.y; - } - } - }, - _setCurrentPoint:function(currentPoint, x, y){ - currentPoint.x = x; - currentPoint.y = y; - }, - _getReflectionPoint:function(centerPoint, point){ - return { - x:centerPoint.x * 2 - point.x, - y:centerPoint.y * 2 - point.y - }; - }, - - /** - * @language=en - * Apply all draw actions. private function. - * @private - */ - _draw: function(context){ - var me = this, actions = me._actions, len = actions.length, i; - - context.beginPath(); - for(i = 0; i < len; i++){ - var action = actions[i], - f = action[0], - args = action.length > 1 ? action.slice(1) : null; - - if(typeof(context[f]) == 'function') context[f].apply(context, args); - else context[f] = action[1]; - } - }, - - /** - * @language=en - * Overwrite render function. - * @private - */ - render: function(renderer, delta){ - var me = this; - if(renderer.renderType === 'canvas'){ - me._draw(renderer.context); - }else{ - me.cache(); - renderer.draw(me); - } - }, - - /** - * @language=en - * Clear all draw actions and reset to the initial state. - * @returns {Graphics} The Graphics Object. - */ - clear: function(){ - var me = this; - - me._actions.length = 0; - me.lineWidth = 1; - me.lineAlpha = 1; - me.lineCap = null; - me.lineJoin = null; - me.miterLimit = 10; - me.hasStroke = false; - me.strokeStyle = '0'; - me.hasFill = false; - me.fillStyle = '0'; - me.fillAlpha = 1; - - me.setCacheDirty(true); - return me; - }, - - /** - * @language=en - * Add a draw action, this is a private function. - * @private - */ - _addAction: function(action){ - var me = this; - me._actions.push(action); - return me; - } - -}); - -})(); - -window.Hilo.Graphics = Graphics; -})(window); \ No newline at end of file +!function(t){t.Hilo||(t.Hilo={});var e=t.Hilo,i=t.Hilo.Class,l=t.Hilo.View,n=t.Hilo.CacheMixin,a=function(){var t=document.createElement("canvas"),r=t.getContext&&t.getContext("2d");return i.create({Extends:l,Mixes:n,constructor:function(t){t=t||{},this.id=this.id||t.id||e.getUid("Graphics"),a.superclass.constructor.call(this,t),this._actions=[]},lineWidth:1,lineAlpha:1,lineCap:null,lineJoin:null,miterLimit:10,hasStroke:!1,strokeStyle:"0",hasFill:!1,fillStyle:"0",fillAlpha:0,lineStyle:function(t,e,i,l,n,a){var r=this,o=r._addAction;return o.call(r,["lineWidth",r.lineWidth=t||1]),o.call(r,["strokeStyle",r.strokeStyle=e||"0"]),o.call(r,["lineAlpha",r.lineAlpha=i||1]),void 0!=l&&o.call(r,["lineCap",r.lineCap=l]),void 0!=n&&o.call(r,["lineJoin",r.lineJoin=n]),void 0!=a&&o.call(r,["miterLimit",r.miterLimit=a]),r.hasStroke=!0,r},setLineDash:function(t){return this._addAction(["setLineDash",t])},beginFill:function(t,e){var i=this,l=i._addAction;return l.call(i,["fillStyle",i.fillStyle=t]),l.call(i,["fillAlpha",i.fillAlpha=e||1]),i.hasFill=!0,i},endFill:function(){var t=this,e=t._addAction;return t.hasStroke&&e.call(t,["stroke"]),t.hasFill&&e.call(t,["fill"]),t.setCacheDirty(!0),t},beginLinearGradientFill:function(t,e,i,l,n,a){for(var o=this,c=r.createLinearGradient(t,e,i,l),s=0,h=n.length;s1?a.slice(1):null;"function"==typeof t[r]?t[r].apply(t,o):t[r]=a[1]}},render:function(t,e){var i=this;"canvas"===t.renderType?i._draw(t.context):(i.cache(),t.draw(i))},clear:function(){var t=this;return t._actions.length=0,t.lineWidth=1,t.lineAlpha=1,t.lineCap=null,t.lineJoin=null,t.miterLimit=10,t.hasStroke=!1,t.strokeStyle="0",t.hasFill=!1,t.fillStyle="0",t.fillAlpha=1,t.setCacheDirty(!0),t},_addAction:function(t){var e=this;return e._actions.push(t),e}})}();t.Hilo.Graphics=a}(window); \ No newline at end of file diff --git a/build/standalone/hilo/view/Sprite.js b/build/standalone/hilo/view/Sprite.js index d9d38f65..fa4d1ec1 100644 --- a/build/standalone/hilo/view/Sprite.js +++ b/build/standalone/hilo/view/Sprite.js @@ -1,5 +1,5 @@ /** - * Hilo 1.5.0 for standalone + * Hilo 1.6.0 for standalone * Copyright 2016 alibaba.com * Licensed under the MIT License */ diff --git a/build/standalone/hilo/view/Sprite.min.js b/build/standalone/hilo/view/Sprite.min.js index 755b0713..a956bbad 100644 --- a/build/standalone/hilo/view/Sprite.min.js +++ b/build/standalone/hilo/view/Sprite.min.js @@ -1,277 +1,6 @@ /** - * Hilo 1.5.0 for standalone + * Hilo 1.6.0 for standalone * Copyright 2016 alibaba.com * Licensed under the MIT License */ -/** - * Hilo 1.5.0 for standalone - * Copyright 2016 alibaba.com - * Licensed under the MIT License - */ -(function(window){ -if(!window.Hilo) window.Hilo = {}; -var Hilo = window.Hilo;var Class = window.Hilo.Class; -var View = window.Hilo.View; -var Drawable = window.Hilo.Drawable; - - -/** - * @language=en - * - *
    - * @class Sprite animation class. - * @augments View - * @module hilo/view/Sprite - * @requires hilo/core/Hilo - * @requires hilo/core/Class - * @requires hilo/view/View - * @requires hilo/view/Drawable - * @param properties Properties parameters for creating object, include all writable properties of this class, also include: - *
      - *
    • frames - Sprite animation frames data object.
    • - *
    - * @property {number} currentFrame Current showing frame index, range from 0, readoly! - * @property {boolean} paused Is sprite paused, default value is false. - * @property {boolean} loop Is sprite play in loop, default value is false. - * @property {boolean} timeBased Is sprite animate base on time, default value is false (base on frame). - * @property {number} interval Interval between sprite animation frames. If timeBased is true, measured in ms, otherwise, measured in frames. - */ -var Sprite = Class.create(/** @lends Sprite.prototype */{ - Extends: View, - constructor: function(properties){ - properties = properties || {}; - this.id = this.id || properties.id || Hilo.getUid("Sprite"); - Sprite.superclass.constructor.call(this, properties); - - this._frames = []; - this._frameNames = {}; - this.drawable = new Drawable(); - if(properties.frames) this.addFrame(properties.frames); - }, - - _frames: null, //所有帧的集合 Collection of all frames - _frameNames: null, //带名字name的帧的集合 Collection of frames that with name - _frameElapsed: 0, //当前帧持续的时间或帧数 Elapsed time of current frame. - _firstRender: true, //标记是否是第一次渲染 Is the first render. - - paused: false, - loop: true, - timeBased: false, - interval: 1, - currentFrame: 0, //当前帧的索引 Index of current frame - - /** - * @language=en - * Return the total amount of sprite animation frames. - * @returns {Uint} The total amount of frames. - */ - getNumFrames: function(){ - return this._frames ? this._frames.length : 0; - }, - - /** - * @language=en - * Add frame into sprite. - * @param {Object} frame Frames to add into. - * @param {Int} startIndex The index to start adding frame, if is not given, add at the end of sprite. - * @returns {Sprite} Sprite itself. - */ - addFrame: function(frame, startIndex){ - var start = startIndex != null ? startIndex : this._frames.length; - if(frame instanceof Array){ - for(var i = 0, len = frame.length; i < len; i++){ - this.setFrame(frame[i], start + i); - } - }else{ - this.setFrame(frame, start); - } - return this; - }, - - /** - * @language=en - * Set the frame on the given index. - * @param {Object} frame The frame data to set on that index. - * @param {Int} index Index of the frame to set. - * @returns {Sprite} Sprite itself. - */ - setFrame: function(frame, index){ - var frames = this._frames, - total = frames.length; - index = index < 0 ? 0 : index > total ? total : index; - frames[index] = frame; - if(frame.name) this._frameNames[frame.name] = frame; - if(index == 0 && !this.width || !this.height){ - this.width = frame.rect[2]; - this.height = frame.rect[3]; - } - return this; - }, - - /** - * @language=en - * Get the frame of given parameter from sprite. - * @param {Object} indexOrName The index or name of the frame. - * @returns {Object} The sprite object. - */ - getFrame: function(indexOrName){ - if(typeof indexOrName === 'number'){ - var frames = this._frames; - if(indexOrName < 0 || indexOrName >= frames.length) return null; - return frames[indexOrName]; - } - return this._frameNames[indexOrName]; - }, - - /** - * @language=en - * Get frame index from sprite. - * @param {Object} frameValue Index or name of the frame. - * @returns {Object} Sprite frame object. - */ - getFrameIndex: function(frameValue){ - var frames = this._frames, - total = frames.length, - index = -1; - if(typeof frameValue === 'number'){ - index = frameValue; - }else{ - var frame = typeof frameValue === 'string' ? this._frameNames[frameValue] : frameValue; - if(frame){ - for(var i = 0; i < total; i++){ - if(frame === frames[i]){ - index = i; - break; - } - } - } - } - return index; - }, - - /** - * @language=en - * Play sprite. - * @returns {Sprite} The Sprite object. - */ - play: function(){ - this.paused = false; - return this; - }, - - /** - * @language=en - * Pause playing sprite. - * @returns {Sprite} The Sprite object. - */ - stop: function(){ - this.paused = true; - return this; - }, - - /** - * @language=en - * Jump to an assigned frame. - * @param {Object} indexOrName Index or name of an frame to jump to. - * @param {Boolean} pause Does pause after jumping to the new index. - * @returns {Sprite} The Sprite object. - */ - goto: function(indexOrName, pause){ - var total = this._frames.length, - index = this.getFrameIndex(indexOrName); - - this.currentFrame = index < 0 ? 0 : index >= total ? total - 1 : index; - this.paused = pause; - this._firstRender = true; - return this; - }, - - /** - * @language=en - * Render function. - * @private - */ - _render: function(renderer, delta){ - var lastFrameIndex = this.currentFrame, frameIndex; - - if(this._firstRender){ - frameIndex = lastFrameIndex; - this._firstRender = false; - }else{ - frameIndex = this._nextFrame(delta); - } - - if(frameIndex != lastFrameIndex){ - this.currentFrame = frameIndex; - var callback = this._frames[frameIndex].callback; - callback && callback.call(this); - } - - //NOTE: it will be deprecated, don't use it. - if(this.onEnterFrame) this.onEnterFrame(frameIndex); - - this.drawable.init(this._frames[frameIndex]); - Sprite.superclass._render.call(this, renderer, delta); - }, - - /** - * @language=en - * @private - */ - _nextFrame: function(delta){ - var frames = this._frames, - total = frames.length, - frameIndex = this.currentFrame, - frame = frames[frameIndex], - duration = frame.duration || this.interval, - elapsed = this._frameElapsed; - - //calculate the current frame elapsed frames/time - var value = (frameIndex == 0 && !this.drawable) ? 0 : elapsed + (this.timeBased ? delta : 1); - elapsed = this._frameElapsed = value < duration ? value : 0; - - if(frame.stop || !this.loop && frameIndex >= total - 1){ - this.stop(); - } - - if(!this.paused && elapsed == 0){ - if(frame.next != null){ - //jump to the specified frame - frameIndex = this.getFrameIndex(frame.next); - }else if(frameIndex >= total - 1){ - //at the end of the frames, go back to first frame - frameIndex = 0; - }else if(this.drawable){ - //normal go forward to next frame - frameIndex++; - } - } - - return frameIndex; - }, - - /** - * @language=en - * Set a callback on an assigned frame. Every time assigned frame is played, invoke the callback function. If callback is empty, callback function will be removed. - * @param {Int|String} frame Index or name of the assigned frame. - * @param {Function} callback Callback function. - * @returns {Sprite} The Sprite object. - */ - setFrameCallback: function(frame, callback){ - frame = this.getFrame(frame); - if(frame) frame.callback = callback; - return this; - }, - - /** - * @language=en - * Callback function on when sprite enter a new frame. default value is null. Note: this function is obsolete, use addFrameCallback funciton instead. - * @type Function - * @deprecated - */ - onEnterFrame: null - -}); - -window.Hilo.Sprite = Sprite; -})(window); \ No newline at end of file +!function(e){e.Hilo||(e.Hilo={});var t=e.Hilo,r=e.Hilo.Class,s=e.Hilo.View,i=e.Hilo.Drawable,a=r.create({Extends:s,constructor:function(e){e=e||{},this.id=this.id||e.id||t.getUid("Sprite"),a.superclass.constructor.call(this,e),this._frames=[],this._frameNames={},this.drawable=new i,e.frames&&this.addFrame(e.frames)},_frames:null,_frameNames:null,_frameElapsed:0,_firstRender:!0,paused:!1,loop:!0,timeBased:!1,interval:1,currentFrame:0,getNumFrames:function(){return this._frames?this._frames.length:0},addFrame:function(e,t){var r=null!=t?t:this._frames.length;if(e instanceof Array)for(var s=0,i=e.length;ss?s:t,r[t]=e,e.name&&(this._frameNames[e.name]=e),(0!=t||this.width)&&this.height||(this.width=e.rect[2],this.height=e.rect[3]),this},getFrame:function(e){if("number"==typeof e){var t=this._frames;return e<0||e>=t.length?null:t[e]}return this._frameNames[e]},getFrameIndex:function(e){var t=this._frames,r=t.length,s=-1;if("number"==typeof e)s=e;else{var i="string"==typeof e?this._frameNames[e]:e;if(i)for(var a=0;a=r?r-1:s,this.paused=t,this._firstRender=!0,this},_render:function(e,t){var r,s=this.currentFrame;if(this._firstRender?(r=s,this._firstRender=!1):r=this._nextFrame(t),r!=s){this.currentFrame=r;var i=this._frames[r].callback;i&&i.call(this)}this.onEnterFrame&&this.onEnterFrame(r),this.drawable.init(this._frames[r]),a.superclass._render.call(this,e,t)},_nextFrame:function(e){var t=this._frames,r=t.length,s=this.currentFrame,i=t[s],a=i.duration||this.interval,n=this._frameElapsed,h=0!=s||this.drawable?n+(this.timeBased?e:1):0;return n=this._frameElapsed=h=r-1)&&this.stop(),this.paused||0!=n||(null!=i.next?s=this.getFrameIndex(i.next):s>=r-1?s=0:this.drawable&&s++),s},setFrameCallback:function(e,t){return e=this.getFrame(e),e&&(e.callback=t),this},onEnterFrame:null});e.Hilo.Sprite=a}(window); \ No newline at end of file diff --git a/build/standalone/hilo/view/Stage.js b/build/standalone/hilo/view/Stage.js index 2e7e2028..15a1562e 100644 --- a/build/standalone/hilo/view/Stage.js +++ b/build/standalone/hilo/view/Stage.js @@ -1,5 +1,5 @@ /** - * Hilo 1.5.0 for standalone + * Hilo 1.6.0 for standalone * Copyright 2016 alibaba.com * Licensed under the MIT License */ diff --git a/build/standalone/hilo/view/Stage.min.js b/build/standalone/hilo/view/Stage.min.js index a945b842..a7e6367c 100644 --- a/build/standalone/hilo/view/Stage.min.js +++ b/build/standalone/hilo/view/Stage.min.js @@ -1,277 +1,6 @@ /** - * Hilo 1.5.0 for standalone + * Hilo 1.6.0 for standalone * Copyright 2016 alibaba.com * Licensed under the MIT License */ -/** - * Hilo 1.5.0 for standalone - * Copyright 2016 alibaba.com - * Licensed under the MIT License - */ -(function(window){ -if(!window.Hilo) window.Hilo = {}; -var Hilo = window.Hilo;var Class = window.Hilo.Class; -var Container = window.Hilo.Container; -var CanvasRenderer = window.Hilo.CanvasRenderer; -var DOMRenderer = window.Hilo.DOMRenderer; -var WebGLRenderer = window.Hilo.WebGLRenderer; -var browser = window.Hilo.browser; -var util = window.Hilo.util; - - -/** - * @language=en - * Demo: - *
    - * var stage = new Hilo.Stage({
    - *     renderType:'canvas',
    - *     container: containerElement,
    - *     width: 320,
    - *     height: 480
    - * });
    - * 
    - * @class Stage is the root of all visual object tree, any visual object will be render only after being added to Stage or any children elements of Stage. Normally, every hilo application start with an stage instance. - * @augments Container - * @param {Object} properties Properties parameters for the object. Includes all writable properties of this class. Some important like: - *
      - *
    • container:String|HTMLElement - Assign the parent container element of the Stage in the page. It should be a dom container or an id. If this parameter is not given and canvas isn't in the dom tree, you should add the stage vanvas into the dom tree yourself, otherwise Stage will not render. optional.
    • - *
    • renderType:String - Renering way: canvas|dom|webgl,default value is canvas, optional.
    • - *
    • canvas:String|HTMLCanvasElement|HTMLElement - 指定舞台所对应的画布元素。它是一个canvas或普通的div,也可以传入元素的id。若为canvas,则使用canvas来渲染所有对象,否则使用dom+css来渲染。可选。
    • - *
    • width:Number
    • - The width of the Stage, default value is the width of canvas, optional. - *
    • height:Number
    • - The height of the Stage, default value is the height of canvas, optional. - *
    • paused:Boolean
    • - Whether stop rendering the Stage, default value is false, optional. - *
    - * @module hilo/view/Stage - * @requires hilo/core/Hilo - * @requires hilo/core/Class - * @requires hilo/view/Container - * @requires hilo/renderer/CanvasRenderer - * @requires hilo/renderer/DOMRenderer - * @requires hilo/renderer/WebGLRenderer - * @requires hilo/util/browser - * @requires hilo/util/util - * @property {HTMLCanvasElement|HTMLElement} canvas The canvas the Stage is related to. It can be a canvas or a div element, readonly! - * @property {Renderer} renderer Stage renderer, readonly! - * @property {Boolean} paused Paused Stage rendering. - * @property {Object} viewport Rendering area of the Stage. Including properties like: left, top, width, height. readonly! - */ -var Stage = Class.create(/** @lends Stage.prototype */{ - Extends: Container, - constructor: function(properties){ - properties = properties || {}; - this.id = this.id || properties.id || Hilo.getUid('Stage'); - Stage.superclass.constructor.call(this, properties); - - this._initRenderer(properties); - - //init size - var width = this.width, height = this.height, - viewport = this.updateViewport(); - if(!properties.width) width = (viewport && viewport.width) || 320; - if(!properties.height) height = (viewport && viewport.height) || 480; - this.resize(width, height, true); - }, - - canvas: null, - renderer: null, - paused: false, - viewport: null, - - /** - * @language=en - * @private - */ - _initRenderer: function(properties){ - var canvas = properties.canvas; - var container = properties.container; - var renderType = properties.renderType||'canvas'; - - if(typeof canvas === 'string') canvas = Hilo.getElement(canvas); - if(typeof container === 'string') container = Hilo.getElement(container); - - if(!canvas){ - var canvasTagName = renderType === 'dom'?'div':'canvas'; - canvas = Hilo.createElement(canvasTagName, { - style: { - position: 'absolute' - } - }); - } - else if(!canvas.getContext){ - renderType = 'dom'; - } - - this.canvas = canvas; - if(container) container.appendChild(canvas); - - var props = {canvas:canvas, stage:this}; - switch(renderType){ - case 'dom': - this.renderer = new DOMRenderer(props); - break; - case 'webgl': - if(WebGLRenderer.isSupport()){ - this.renderer = new WebGLRenderer(props); - } - else{ - this.renderer = new CanvasRenderer(props); - } - break; - case 'canvas': - /* falls through */ - default: - this.renderer = new CanvasRenderer(props); - break; - } - }, - - /** - * @language=en - * Add Stage canvas to DOM container. Note: this function overwrite View.addTo function. - * @param {HTMLElement} domElement An dom element. - * @returns {Stage} The Stage Object, chained call supported. - */ - addTo: function(domElement){ - var canvas = this.canvas; - if(canvas.parentNode !== domElement){ - domElement.appendChild(canvas); - } - return this; - }, - - /** - * @language=en - * Invoke tick function and Stage will update and render. Developer may not need to use this funciton. - * @param {Number} delta The time had pass between this tick invoke and last tick invoke. - */ - tick: function(delta){ - if(!this.paused){ - this._render(this.renderer, delta); - } - }, - - /** - * @language=en - * Turn on/off Stage response to DOM event. To make visual objects on the Stage interactive, use this function to turn on Stage's responses to events. - * @param {String|Array} type The event name or array that need to turn on/off. - * @param {Boolean} enabled Whether turn on or off the response method of stage DOM event. If not provided, default value is true. - * @returns {Stage} The Stage Object, chained call supported. - */ - enableDOMEvent: function(types, enabled){ - var me = this, - canvas = me.canvas, - handler = me._domListener || (me._domListener = function(e){me._onDOMEvent(e);}); - - types = typeof types === 'string' ? [types] : types; - enabled = enabled !== false; - - for(var i = 0; i < types.length; i++){ - var type = types[i]; - - if(enabled){ - canvas.addEventListener(type, handler, false); - }else{ - canvas.removeEventListener(type, handler); - } - } - - return me; - }, - - /** - * @language=en - * DOM events handler function. This funciton will invoke events onto the visual object, which is on the position of the coordinate where the events is invoked. - * @private - */ - _onDOMEvent: function(e){ - var type = e.type, event = e, isTouch = type.indexOf('touch') == 0; - - //calculate stageX/stageY - var posObj = e; - if(isTouch){ - var touches = e.touches, changedTouches = e.changedTouches; - posObj = (touches && touches.length) ? touches[0] : - (changedTouches && changedTouches.length) ? changedTouches[0] : null; - } - - var x = posObj.pageX || posObj.clientX, y = posObj.pageY || posObj.clientY, - viewport = this.viewport || this.updateViewport(); - - event.stageX = x = (x - viewport.left) / this.scaleX; - event.stageY = y = (y - viewport.top) / this.scaleY; - - //鼠标事件需要阻止冒泡方法 Prevent bubbling on mouse events. - event.stopPropagation = function(){ - this._stopPropagationed = true; - }; - - var obj = this.getViewAtPoint(x, y, true, false, true)||this, - canvas = this.canvas, target = this._eventTarget; - - //fire mouseout/touchout event for last event target - var leave = type === 'mouseout'; - //当obj和target不同 且obj不是target的子元素时才触发out事件 fire out event when obj and target isn't the same as well as obj is not a child element to target. - if(target && (target != obj && (!target.contains || !target.contains(obj))|| leave)){ - var out = (type === 'touchmove') ? 'touchout' : - (type === 'mousemove' || leave || !obj) ? 'mouseout' : null; - if(out) { - var outEvent = util.copy({}, event); - outEvent.type = out; - outEvent.eventTarget = target; - target._fireMouseEvent(outEvent); - } - event.lastEventTarget = target; - this._eventTarget = null; - } - - //fire event for current view - if(obj && obj.pointerEnabled && type !== 'mouseout'){ - event.eventTarget = this._eventTarget = obj; - obj._fireMouseEvent(event); - } - - //set cursor for current view - if(!isTouch){ - var cursor = (obj && obj.pointerEnabled && obj.useHandCursor) ? 'pointer' : ''; - canvas.style.cursor = cursor; - } - - //fix android: `touchmove` fires only once - if(browser.android && type === 'touchmove'){ - e.preventDefault(); - } - }, - - /** - * @language=en - * Update the viewport (rendering area) which Stage show on the page. Invoke this function to update viewport when Stage canvas changes border, margin or padding properties. - * @returns {Object} The visible area of the Stage (the viewport property). - */ - updateViewport: function(){ - var canvas = this.canvas, viewport = null; - if(canvas.parentNode){ - viewport = this.viewport = Hilo.getElementRect(canvas); - } - return viewport; - }, - - /** - * @language=en - * Resize the Stage. - * @param {Number} width The width of the new Stage. - * @param {Number} height The height of the new Stage. - * @param {Boolean} forceResize Whether forced to resize the Stage, means no matter the size of the Stage, force to change the size to keep Stage, canvas and window act at the same time. - */ - resize: function(width, height, forceResize){ - if(forceResize || this.width !== width || this.height !== height){ - this.width = width; - this.height = height; - this.renderer.resize(width, height); - this.updateViewport(); - } - } - -}); - -window.Hilo.Stage = Stage; -})(window); \ No newline at end of file +!function(e){e.Hilo||(e.Hilo={});var t=e.Hilo,i=e.Hilo.Class,n=e.Hilo.Container,r=e.Hilo.CanvasRenderer,s=e.Hilo.DOMRenderer,a=e.Hilo.WebGLRenderer,o=e.Hilo.browser,h=e.Hilo.util,d=i.create({Extends:n,constructor:function(e){e=e||{},this.id=this.id||e.id||t.getUid("Stage"),d.superclass.constructor.call(this,e),this._initRenderer(e);var i=this.width,n=this.height,r=this.updateViewport();e.width||(i=r&&r.width||320),e.height||(n=r&&r.height||480),this.resize(i,n,!0)},canvas:null,renderer:null,paused:!1,viewport:null,_initRenderer:function(e){var i=e.canvas,n=e.container,o=e.renderType||"canvas";if("string"==typeof i&&(i=t.getElement(i)),"string"==typeof n&&(n=t.getElement(n)),i)i.getContext||(o="dom");else{var h="dom"===o?"div":"canvas";i=t.createElement(h,{style:{position:"absolute"}})}this.canvas=i,n&&n.appendChild(i);var d={canvas:i,stage:this};switch(o){case"dom":this.renderer=new s(d);break;case"webgl":a.isSupport()?this.renderer=new a(d):this.renderer=new r(d);break;case"canvas":default:this.renderer=new r(d)}},addTo:function(e){var t=this.canvas;return t.parentNode!==e&&e.appendChild(t),this},tick:function(e){this.paused||this._render(this.renderer,e)},enableDOMEvent:function(e,t){var i=this,n=i.canvas,r=i._domListener||(i._domListener=function(e){i._onDOMEvent(e)});e="string"==typeof e?[e]:e,t=t!==!1;for(var s=0;s - *
    - * @class Text class provide basic text-display function, use DOMElement for complex text-display. - * @augments View - * @mixes CacheMixin - * @borrows CacheMixin#cache as #cache - * @borrows CacheMixin#updateCache as #updateCache - * @borrows CacheMixin#setCacheDirty as #setCacheDirty - * @param {Object} properties Properties parameters for the object. Includes all writable properties. - * @module hilo/view/Text - * @requires hilo/core/Class - * @requires hilo/core/Hilo - * @requires hilo/view/View - * @requires hilo/view/CacheMixin - * @property {String} text Text to display. - * @property {String} color Color of the text. - * @property {String} textAlign Horizontal alignment way of the text. May be one of the following value:'start', 'end', 'left', 'right', and 'center'. Note:Need to specify the width property of the text to take effect - * @property {String} textVAlign Vertical alignment way of the text. May be one of the following value:'top', 'middle', 'bottom'. Note:Need to specify the height property of the text to take effect. - * @property {Boolean} outline Draw the outline of the text or fill the text. - * @property {Number} lineSpacing The spacing between lines. Measured in px, default value is 0. - * @property {Number} maxWidth The max length of the text, default value is 200. - * @property {String} font Text's CSS font style, readonly! Use setFont function to set text font. - * @property {Number} textWidth Width of the text, readonly! Works only on canvas mode. - * @property {Number} textHeight Height of the text, readonly! Works only on canvas mode. - */ -var Text = Class.create(/** @lends Text.prototype */{ - Extends: View, - Mixes:CacheMixin, - constructor: function(properties){ - properties = properties || {}; - this.id = this.id || properties.id || Hilo.getUid('Text'); - Text.superclass.constructor.call(this, properties); - - // if(!properties.width) this.width = 200; //default width - if(!properties.font) this.font = '12px arial'; //default font style - this._fontHeight = Text.measureFontHeight(this.font); - }, - - text: '', - color: '#000', - textAlign: null, - textVAlign: null, - outline: false, - lineSpacing: 0, - maxWidth: 200, - font: null, //ready-only - textWidth: 0, //read-only - textHeight: 0, //read-only - - /** - * @language=en - * Set text CSS font style. - * @param {String} font Text CSS font style to set. - * @returns {Text} the Text object, chained call supported. - */ - setFont: function(font){ - var me = this; - if(me.font !== font){ - me.font = font; - me._fontHeight = Text.measureFontHeight(font); - } - - return me; - }, - - /** - * @language=en - * Overwrite render function. - * @private - */ - render: function(renderer, delta){ - var me = this; - - if(renderer.renderType === 'canvas'){ - if(this.drawable){ - renderer.draw(me); - } - else{ - me._draw(renderer.context); - } - } - else if(renderer.renderType === 'dom'){ - var drawable = me.drawable; - var domElement = drawable.domElement; - var style = domElement.style; - - style.font = me.font; - style.textAlign = me.textAlign; - style.color = me.color; - style.width = me.width + 'px'; - style.height = me.height + 'px'; - style.lineHeight = (me._fontHeight + me.lineSpacing) + 'px'; - - domElement.innerHTML = me.text; - renderer.draw(this); - } - else{ - //TODO:自动更新cache TODO:auto update cache - me.cache(); - renderer.draw(me); - } - }, - - /** - * @language=en - * Draw text under the assigned render context. - * @private - */ - _draw: function(context){ - var me = this, text = me.text.toString(); - if(!text) return; - - //set drawing style - context.font = me.font; - context.textAlign = me.textAlign; - context.textBaseline = 'top'; - - //find and draw all explicit lines - var lines = text.split(/\r\n|\r|\n|/); - var width = 0, height = 0; - var lineHeight = me._fontHeight + me.lineSpacing; - var i, line, w, len, wlen; - var drawLines = []; - - for(i = 0, len = lines.length; i < len; i++){ - line = lines[i]; - w = context.measureText(line).width; - - //check if the line need to split - if(w <= me.maxWidth){ - drawLines.push({text:line, y:height}); - // me._drawTextLine(context, line, height); - if(width < w) width = w; - height += lineHeight; - continue; - } - - var str = '', oldWidth = 0, newWidth, j, word; - - for(j = 0, wlen = line.length; j < wlen; j++){ - word = line[j]; - newWidth = context.measureText(str + word).width; - - if(newWidth > me.maxWidth){ - drawLines.push({text:str, y:height}); - // me._drawTextLine(context, str, height); - if(width < oldWidth) width = oldWidth; - height += lineHeight; - str = word; - }else{ - oldWidth = newWidth; - str += word; - } - - if(j == wlen - 1){ - drawLines.push({text:str, y:height}); - // me._drawTextLine(context, str, height); - if(str !== word && width < newWidth) width = newWidth; - height += lineHeight; - } - } - } - - me.textWidth = width; - me.textHeight = height; - if(!me.width) me.width = width; - if(!me.height) me.height = height; - - //vertical alignment - var startY = 0; - switch(me.textVAlign){ - case 'middle': - startY = me.height - me.textHeight >> 1; - break; - case 'bottom': - startY = me.height - me.textHeight; - break; - } - - //draw background - var bg = me.background; - if(bg){ - context.fillStyle = bg; - context.fillRect(0, 0, me.width, me.height); - } - - if(me.outline) context.strokeStyle = me.color; - else context.fillStyle = me.color; - - //draw text lines - for(i = 0; i < drawLines.length; i++){ - line = drawLines[i]; - me._drawTextLine(context, line.text, startY + line.y); - } - }, - - /** - * @language=en - * Draw a line of text under the assigned render context. - * @private - */ - _drawTextLine: function(context, text, y){ - var me = this, x = 0, width = me.width; - - switch(me.textAlign){ - case 'center': - x = width >> 1; - break; - case 'right': - case 'end': - x = width; - break; - } - - if(me.outline) context.strokeText(text, x, y); - else context.fillText(text, x, y); - }, - - Statics: /** @lends Text */{ - /** - * @language=en - * Measure the line height of the assigned text font style. - * @param {String} font Font style to measure. - * @return {Number} Return line height of the assigned font style. - */ - measureFontHeight: function(font){ - var docElement = document.documentElement, fontHeight; - var elem = Hilo.createElement('div', {style:{font:font, position:'absolute'}, innerHTML:'M'}); - - docElement.appendChild(elem); - fontHeight = elem.offsetHeight; - docElement.removeChild(elem); - return fontHeight; - } - } - -}); - -window.Hilo.Text = Text; -})(window); \ No newline at end of file +!function(t){t.Hilo||(t.Hilo={});var e=t.Hilo.Class,i=t.Hilo,n=t.Hilo.View,o=t.Hilo.CacheMixin,l=e.create({Extends:n,Mixes:o,constructor:function(t){t=t||{},this.id=this.id||t.id||i.getUid("Text"),l.superclass.constructor.call(this,t),t.font||(this.font="12px arial"),this._fontHeight=l.measureFontHeight(this.font)},text:"",color:"#000",textAlign:null,textVAlign:null,outline:!1,lineSpacing:0,maxWidth:200,font:null,textWidth:0,textHeight:0,setFont:function(t){var e=this;return e.font!==t&&(e.font=t,e._fontHeight=l.measureFontHeight(t)),e},render:function(t,e){var i=this;if("canvas"===t.renderType)this.drawable?t.draw(i):i._draw(t.context);else if("dom"===t.renderType){var n=i.drawable,o=n.domElement,l=o.style;l.font=i.font,l.textAlign=i.textAlign,l.color=i.color,l.width=i.width+"px",l.height=i.height+"px",l.lineHeight=i._fontHeight+i.lineSpacing+"px",o.innerHTML=i.text,t.draw(this)}else i.cache(),t.draw(i)},_draw:function(t){var e=this,i=e.text.toString();if(i){t.font=e.font,t.textAlign=e.textAlign,t.textBaseline="top";var n,o,l,h,r,a=i.split(/\r\n|\r|\n|/),s=0,d=0,c=e._fontHeight+e.lineSpacing,x=[];for(n=0,h=a.length;ne.maxWidth?(x.push({text:w,y:d}),s>1;break;case"bottom":m=e.height-e.textHeight}var p=e.background;for(p&&(t.fillStyle=p,t.fillRect(0,0,e.width,e.height)),e.outline?t.strokeStyle=e.color:t.fillStyle=e.color,n=0;n>1;break;case"right":case"end":o=l}n.outline?t.strokeText(e,o,i):t.fillText(e,o,i)},Statics:{measureFontHeight:function(t){var e,n=document.documentElement,o=i.createElement("div",{style:{font:t,position:"absolute"},innerHTML:"M"});return n.appendChild(o),e=o.offsetHeight,n.removeChild(o),e}}});t.Hilo.Text=l}(window); \ No newline at end of file diff --git a/build/standalone/hilo/view/View.js b/build/standalone/hilo/view/View.js index 3eb663f7..715d4b0b 100644 --- a/build/standalone/hilo/view/View.js +++ b/build/standalone/hilo/view/View.js @@ -1,5 +1,5 @@ /** - * Hilo 1.5.0 for standalone + * Hilo 1.6.0 for standalone * Copyright 2016 alibaba.com * Licensed under the MIT License */ diff --git a/build/standalone/hilo/view/View.min.js b/build/standalone/hilo/view/View.min.js index 2f848f68..f2aa8c97 100644 --- a/build/standalone/hilo/view/View.min.js +++ b/build/standalone/hilo/view/View.min.js @@ -1,504 +1,6 @@ /** - * Hilo 1.5.0 for standalone + * Hilo 1.6.0 for standalone * Copyright 2016 alibaba.com * Licensed under the MIT License */ -/** - * Hilo 1.5.0 for standalone - * Copyright 2016 alibaba.com - * Licensed under the MIT License - */ -(function(window){ -if(!window.Hilo) window.Hilo = {}; -var Hilo = window.Hilo;var Class = window.Hilo.Class; -var EventMixin = window.Hilo.EventMixin; -var Matrix = window.Hilo.Matrix; -var util = window.Hilo.util; - - -/** - * @language=en - * @class View View is the base class of all display objects - * @mixes EventMixin - * @borrows EventMixin#on as #on - * @borrows EventMixin#off as #off - * @borrows EventMixin#fire as #fire - * @param {Object} properties The properties to create a view object, contains all writeable props of this class - * @module hilo/view/View - * @requires hilo/core/Hilo - * @requires hilo/core/Class - * @requires hilo/event/EventMixin - * @requires hilo/geom/Matrix - * @requires hilo/util/util - * @property {String} id The identifier for the view. - * @property {Number} x The position of the view on the x axis relative to the local coordinates of the parent, default value is 0. - * @property {Number} y The position of the view on the y axis relative to the local coordinates of the parent, default value is 0. - * @property {Number} width The width of the view, default value is 0. - * @property {Number} height The height of the view, default value is 0. - * @property {Number} alpha The opacity of the view, default value is 1. - * @property {Number} rotation The rotation of the view in angles, default value is 0. - * @property {Boolean} visible The visibility of the view. If false the vew will not be drawn, default value is true. - * @property {Number} pivotX Position of the center point on the x axis of the view, default value is 0. - * @property {Number} pivotY Position of the center point on the y axis of the view, default value is 0. - * @property {Number} scaleX The x axis scale factor of the view, default value is 1. - * @property {Number} scaleY The y axis scale factor of the view, default value is 1. - * @property {Matrix} transform The transform of the view.If set the transform, x, y, scaleX, scaleY, rotation, pivotX, pivotY will be ignored.default is null. - * @property {Boolean} pointerEnabled Is the view can receive DOM events, default value is true. - * @property {Object} background The background style to fill the view, can be css color, gradient or pattern of canvas - * @property {Graphics} mask Sets a mask for the view. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. A regular mask must be a Hilo.Graphics object. This allows for much faster masking in canvas as it utilises shape clipping. To remove a mask, set this property to null. - * @property {Number} tint The tint applied to the view,default is 0xFFFFFF.Only support in WebGL mode. - * @property {String|Function} align The alignment of the view, the value must be one of Hilo.align enum. - * @property {Container} parent The parent view of this view, readonly! - * @property {Number} depth The z index of the view, readonly! - * @property {Drawable} drawable The drawable object of the view. Only for advanced develop. - * @property {Array} boundsArea The vertex points of the view, the points are relative to the center point. This is a example: [{x:10, y:10}, {x:20, y:20}]. - */ -var View = (function(){ - -return Class.create(/** @lends View.prototype */{ - Mixes: EventMixin, - constructor: function(properties){ - properties = properties || {}; - this.id = this.id || properties.id || Hilo.getUid("View"); - util.copy(this, properties, true); - }, - - tint:0xffffff, - id: null, - x: 0, - y: 0, - width: 0, - height: 0, - alpha: 1, - rotation: 0, - visible: true, - pivotX: 0, - pivotY: 0, - scaleX: 1, - scaleY: 1, - pointerEnabled: true, - background: null, - mask: null, - align: null, - drawable: null, - boundsArea: null, - parent: null, - depth: -1, - transform: null, - blendMode:'source-over', - - /** - * @language=en - * Get the stage object of the view. If the view doesn't add to any stage, null will be returned. - * @returns {Stage} The stage object of the view. - */ - getStage: function(){ - var obj = this, parent; - while(parent = obj.parent) obj = parent; - //NOTE: don't use `instanceof` to prevent circular module requirement. - //But it's not a very reliable way to check it's a stage instance. - if(obj.canvas) return obj; - return null; - }, - - /** - * @language=en - * Get the scaled width of the view. - * @returns {Number} scaled width of the view. - */ - getScaledWidth: function(){ - return this.width * this.scaleX; - }, - - /** - * @language=en - * Get the scaled height of the view. - * @returns {Number} scaled height of the view. - */ - getScaledHeight: function(){ - return this.height * this.scaleY; - }, - - /** - * @language=en - * Add current view to a Contaner. - * @param {Container} container Container object. - * @param {Uint} index The index of the view in container. - * @returns {View} Current view. - */ - addTo: function(container, index){ - if(typeof index === 'number') container.addChildAt(this, index); - else container.addChild(this); - return this; - }, - - /** - * @language=en - * Remove current view from it's parent container - * @returns {View} Current view. - */ - removeFromParent: function(){ - var parent = this.parent; - if(parent) parent.removeChild(this); - return this; - }, - - /** - * @language=en - * Get the bounds of the view as a circumscribed rectangle and all vertex points relative to the coordinates of the stage. - * @returns {Array} The vertex points array, and the array contains the following properties: - *
      - *
    • x - The position of the view on the x axis relative to the coordinates of the stage.
    • - *
    • y - The position of the view on the y axis relative to the coordinates of the stage.
    • - *
    • width - The width of circumscribed rectangle of the view.
    • - *
    • height - The height of circumscribed rectangle of the view
    • - *
    - */ - getBounds: function(){ - var w = this.width, h = this.height, - mtx = this.getConcatenatedMatrix(), - poly = this.boundsArea || [{x:0, y:0}, {x:w, y:0}, {x:w, y:h}, {x:0, y:h}], - vertexs = [], point, x, y, minX, maxX, minY, maxY; - - for(var i = 0, len = poly.length; i < len; i++){ - point = mtx.transformPoint(poly[i], true, true); - x = point.x; - y = point.y; - - if(i == 0){ - minX = maxX = x; - minY = maxY = y; - }else{ - if(minX > x) minX = x; - else if(maxX < x) maxX = x; - if(minY > y) minY = y; - else if(maxY < y) maxY = y; - } - vertexs[i] = point; - } - - vertexs.x = minX; - vertexs.y = minY; - vertexs.width = maxX - minX; - vertexs.height = maxY - minY; - return vertexs; - }, - - /** - * @language=en - * Get the matrix that can transform points from current view coordinates to the ancestor container coordinates. - * @param {View} ancestor The ancestor of current view, default value is the top container. - * @private - */ - getConcatenatedMatrix: function(ancestor){ - var mtx = new Matrix(1, 0, 0, 1, 0, 0); - - for(var o = this; o != ancestor && o.parent; o = o.parent){ - var cos = 1, sin = 0, - rotation = o.rotation % 360, - pivotX = o.pivotX, pivotY = o.pivotY, - scaleX = o.scaleX, scaleY = o.scaleY, - transform = o.transform; - - if(transform) { - mtx.concat(transform); - } - else{ - if(rotation){ - var r = rotation * Math.PI / 180; - cos = Math.cos(r); - sin = Math.sin(r); - } - - if(pivotX != 0) mtx.tx -= pivotX; - if(pivotY != 0) mtx.ty -= pivotY; - - var pos = o.getAlignPosition(); - mtx.concat(cos*scaleX, sin*scaleX, -sin*scaleY, cos*scaleY, pos.x, pos.y); - } - - } - return mtx; - }, - - getAlignPosition: function(){ - var parent = this.parent; - var align = this.align; - var x = this.x; - var y = this.y; - - if(parent && this.align){ - if(typeof align === 'function'){ - return this.align(); - } - - var w = this.width, h = this.height, - pw = parent.width, ph = parent.height; - switch(align){ - case 'TL': - x = 0; - y = 0; - break; - case 'T': - x = pw - w >> 1; - y = 0; - break; - case 'TR': - x = pw - w; - y = 0; - break; - case 'L': - x = 0; - y = ph - h >> 1; - break; - case 'C': - x = pw - w >> 1; - y = ph - h >> 1; - break; - case 'R': - x = pw - w; - y = ph - h >> 1; - break; - case 'BL': - x = 0; - y = ph - h; - break; - case 'B': - x = pw - w >> 1; - y = ph - h; - break; - case 'BR': - x = pw - w; - y = ph - h; - break; - } - } - - return { - x:x, - y:y - }; - }, - - /** - * @language=en - * Determining whether a point is in the circumscribed rectangle of current view. - * @param {Number} x The x axis relative to the stage coordinates. - * @param {Number} y The y axis relative to the stage coordinates. - * @param {Boolean} usePolyCollision Is use polygon collision, default value is false. - * @returns {Boolean} the point is in the circumscribed rectangle of current view. - */ - hitTestPoint: function(x, y, usePolyCollision){ - var bound = this.getBounds(), - hit = x >= bound.x && x <= bound.x + bound.width && - y >= bound.y && y <= bound.y + bound.height; - - if(hit && usePolyCollision){ - hit = pointInPolygon(x, y, bound); - } - return hit; - }, - - /** - * @language=en - * Determining whether an object is in the circumscribed rectangle of current view. - * @param {View} object The object need to determining. - * @param {Boolean} usePolyCollision Is use polygon collision, default value is false. - */ - hitTestObject: function(object, usePolyCollision){ - var b1 = this.getBounds(), - b2 = object.getBounds(), - hit = b1.x <= b2.x + b2.width && b2.x <= b1.x + b1.width && - b1.y <= b2.y + b2.height && b2.y <= b1.y + b1.height; - - if(hit && usePolyCollision){ - hit = polygonCollision(b1, b2); - } - return !!hit; - }, - - /** - * @language=en - * The method to render current display object. Only for advanced develop. - * @param {Renderer} renderer Renderer object. - * @param {Number} delta The delta time of render. - * @protected - */ - _render: function(renderer, delta){ - if((!this.onUpdate || this.onUpdate(delta) !== false) && renderer.startDraw(this)){ - renderer.transform(this); - this.render(renderer, delta); - renderer.endDraw(this); - } - }, - /** - * @language=en - * Mouse event - */ - _fireMouseEvent:function(e){ - e.eventCurrentTarget = this; - this.fire(e); - - // 处理mouseover事件 mouseover不需要阻止冒泡 - // handle mouseover event, mouseover needn't stop propagation. - if(e.type == "mousemove"){ - if(!this.__mouseOver){ - this.__mouseOver = true; - var overEvent = util.copy({}, e); - overEvent.type = "mouseover"; - this.fire(overEvent); - } - } - else if(e.type == "mouseout"){ - this.__mouseOver = false; - } - - // 向上冒泡 - // handle event propagation - var parent = this.parent; - if(!e._stopped && !e._stopPropagationed && parent){ - if(e.type == "mouseout" || e.type == "touchout"){ - if(!parent.hitTestPoint(e.stageX, e.stageY, true)){ - parent._fireMouseEvent(e); - } - } - else{ - parent._fireMouseEvent(e); - } - } - }, - - /** - * @language=en - * This method will call while the view need update(usually caused by ticker update). This method can return a Boolean value, if return false, the view will not be drawn. - * Limit: If you change the index in it's parent, it will not be drawn correct in current frame but next frame is correct. - * @type Function - * @default null - */ - onUpdate: null, - - /** - * @language=en - * The render method of current view. The subclass can implement it's own render logic by rewrite this function. - * @param {Renderer} renderer Renderer object. - * @param {Number} delta The delta time of render. - */ - render: function(renderer, delta){ - renderer.draw(this); - }, - - /** - * @language=en - * Get a string representing current view. - * @returns {String} string representing current view. - */ - toString: function(){ - return Hilo.viewToString(this); - } -}); - -/** - * @language=en - * @private - */ -function pointInPolygon(x, y, poly){ - var cross = 0, onBorder = false, minX, maxX, minY, maxY; - - for(var i = 0, len = poly.length; i < len; i++){ - var p1 = poly[i], p2 = poly[(i+1)%len]; - - if(p1.y == p2.y && y == p1.y){ - p1.x > p2.x ? (minX = p2.x, maxX = p1.x) : (minX = p1.x, maxX = p2.x); - if(x >= minX && x <= maxX){ - onBorder = true; - continue; - } - } - - p1.y > p2.y ? (minY = p2.y, maxY = p1.y) : (minY = p1.y, maxY = p2.y); - if(y < minY || y > maxY) continue; - - var nx = (y - p1.y)*(p2.x - p1.x) / (p2.y - p1.y) + p1.x; - if(nx > x) cross++; - else if(nx == x) onBorder = true; - - //当射线和多边形相交 - if(p1.x > x && p1.y == y){ - var p0 = poly[(len+i-1)%len]; - //当交点的两边在射线两旁 - if(p0.y < y && p2.y > y || p0.y > y && p2.y < y){ - cross ++; - } - } - } - - return onBorder || (cross % 2 == 1); -} - -/** - * @language=en - * @private - */ -function polygonCollision(poly1, poly2){ - var result = doSATCheck(poly1, poly2, {overlap:-Infinity, normal:{x:0, y:0}}); - if(result) return doSATCheck(poly2, poly1, result); - return false; -} - -/** - * @language=en - * @private - */ -function doSATCheck(poly1, poly2, result){ - var len1 = poly1.length, len2 = poly2.length, - currentPoint, nextPoint, distance, - min1, max1, min2, max2, dot, overlap, normal = {x:0, y:0}; - - for(var i = 0; i < len1; i++){ - currentPoint = poly1[i]; - nextPoint = poly1[(i < len1-1 ? i+1 : 0)]; - - normal.x = currentPoint.y - nextPoint.y; - normal.y = nextPoint.x - currentPoint.x; - - distance = Math.sqrt(normal.x * normal.x + normal.y * normal.y); - normal.x /= distance; - normal.y /= distance; - - min1 = max1 = poly1[0].x * normal.x + poly1[0].y * normal.y; - for(var j = 1; j < len1; j++){ - dot = poly1[j].x * normal.x + poly1[j].y * normal.y; - if(dot > max1) max1 = dot; - else if(dot < min1) min1 = dot; - } - - min2 = max2 = poly2[0].x * normal.x + poly2[0].y * normal.y; - for(j = 1; j < len2; j++){ - dot = poly2[j].x * normal.x + poly2[j].y * normal.y; - if(dot > max2) max2 = dot; - else if(dot < min2) min2 = dot; - } - - if(min1 < min2){ - overlap = min2 - max1; - normal.x = -normal.x; - normal.y = -normal.y; - }else{ - overlap = min1 - max2; - } - - if(overlap >= 0){ - return false; - }else if(overlap > result.overlap){ - result.overlap = overlap; - result.normal.x = normal.x; - result.normal.y = normal.y; - } - } - - return result; -} - -})(); -window.Hilo.View = View; -})(window); \ No newline at end of file +!function(t){t.Hilo||(t.Hilo={});var e=t.Hilo,i=t.Hilo.Class,n=t.Hilo.EventMixin,r=t.Hilo.Matrix,o=t.Hilo.util,a=function(){function t(t,e,i){for(var n,r,o,a,s=0,h=!1,u=0,l=i.length;uc.x?(n=c.x,r=y.x):(n=y.x,r=c.x),t>=n&&t<=r))h=!0;else if(y.y>c.y?(o=c.y,a=y.y):(o=y.y,a=c.y),!(ea)){var x=(e-y.y)*(c.x-y.x)/(c.y-y.y)+y.x;if(x>t?s++:x==t&&(h=!0),y.x>t&&y.y==e){var d=i[(l+u-1)%l];(d.ye||d.y>e&&c.ys?s=l:lu?u=l:l=0)return!1;y>i.overlap&&(i.overlap=y,i.normal.x=d.x,i.normal.y=d.y)}return i}return i.create({Mixes:n,constructor:function(t){t=t||{},this.id=this.id||t.id||e.getUid("View"),o.copy(this,t,!0)},tint:16777215,id:null,x:0,y:0,width:0,height:0,alpha:1,rotation:0,visible:!0,pivotX:0,pivotY:0,scaleX:1,scaleY:1,pointerEnabled:!0,background:null,mask:null,align:null,drawable:null,boundsArea:null,parent:null,depth:-1,transform:null,blendMode:"source-over",getStage:function(){for(var t,e=this;t=e.parent;)e=t;return e.canvas?e:null},getScaledWidth:function(){return this.width*this.scaleX},getScaledHeight:function(){return this.height*this.scaleY},addTo:function(t,e){return"number"==typeof e?t.addChildAt(this,e):t.addChild(this),this},removeFromParent:function(){var t=this.parent;return t&&t.removeChild(this),this},getBounds:function(){for(var t,e,i,n,r,o,a,s=this.width,h=this.height,u=this.getConcatenatedMatrix(),l=this.boundsArea||[{x:0,y:0},{x:s,y:0},{x:s,y:h},{x:0,y:h}],y=[],c=0,x=l.length;ce?n=e:ri?o=i:a>1,n=0;break;case"TR":i=a-r,n=0;break;case"L":i=0,n=s-o>>1;break;case"C":i=a-r>>1,n=s-o>>1;break;case"R":i=a-r,n=s-o>>1;break;case"BL":i=0,n=s-o;break;case"B":i=a-r>>1,n=s-o;break;case"BR":i=a-r,n=s-o}}return{x:i,y:n}},hitTestPoint:function(e,i,n){var r=this.getBounds(),o=e>=r.x&&e<=r.x+r.width&&i>=r.y&&i<=r.y+r.height;return o&&n&&(o=t(e,i,r)),o},hitTestObject:function(t,e){var i=this.getBounds(),n=t.getBounds(),r=i.x<=n.x+n.width&&n.x<=i.x+i.width&&i.y<=n.y+n.height&&n.y<=i.y+i.height;return r&&e&&(r=a(i,n)),!!r},_render:function(t,e){this.onUpdate&&this.onUpdate(e)===!1||!t.startDraw(this)||(t.transform(this),this.render(t,e),t.endDraw(this))},_fireMouseEvent:function(t){if(t.eventCurrentTarget=this,this.fire(t),"mousemove"==t.type){if(!this.__mouseOver){this.__mouseOver=!0;var e=o.copy({},t);e.type="mouseover",this.fire(e)}}else"mouseout"==t.type&&(this.__mouseOver=!1);var i=this.parent;t._stopped||t._stopPropagationed||!i||("mouseout"==t.type||"touchout"==t.type?i.hitTestPoint(t.stageX,t.stageY,!0)||i._fireMouseEvent(t):i._fireMouseEvent(t))},onUpdate:null,render:function(t,e){t.draw(this)},toString:function(){return e.viewToString(this)}})}();t.Hilo.View=a}(window); \ No newline at end of file diff --git a/docs/api-en/code/loader/LoadQueue.js b/docs/api-en/code/loader/LoadQueue.js index 939eaa39..e2e9ac13 100644 --- a/docs/api-en/code/loader/LoadQueue.js +++ b/docs/api-en/code/loader/LoadQueue.js @@ -84,6 +84,22 @@ var LoadQueue = Class.create(/** @lends LoadQueue.prototype */{ var item = this.get(id); return item && item.content; }, + /** + * remove resource object content by id or src + * @param {String} specified id or src + */ + removeContent: function(id){ + if(id){ + var source = this._source; + for(var i = 0; i < source.length; i++){ + var item = source[i]; + if(item.id === id || item.src === id){ + source.splice(i, 1); + return; + } + } + } + }, /** * start loading diff --git a/docs/api-en/index.html b/docs/api-en/index.html index a098cf0b..bf8c4d70 100644 --- a/docs/api-en/index.html +++ b/docs/api-en/index.html @@ -188,7 +188,7 @@
    -
    All Class Index(v1.5.0)
    +
    All Class Index(v1.6.0)
    diff --git a/docs/api-en/symbols/LoadQueue.html b/docs/api-en/symbols/LoadQueue.html index 5a5a33a3..e3b93cc4 100644 --- a/docs/api-en/symbols/LoadQueue.html +++ b/docs/api-en/symbols/LoadQueue.html @@ -486,6 +486,24 @@

    Methods

    + + + + + + +
    + + +
    removeContent(specified:String) +
    +
    + + remove resource object content by id or src +
    +
    + LoadQueue +
    @@ -926,6 +944,36 @@

    Constructor

    + + + +
    +
    + + removeContent(specified:String) +
    +
    remove resource object content by id or src
    + + + + +
    +
    parameters
    + +
    + specified:String + — id or src +
    + +
    + + + + + + + +
    diff --git a/docs/api-en/symbols/src/docs_api-en_code_loader_LoadQueue.js.html b/docs/api-en/symbols/src/docs_api-en_code_loader_LoadQueue.js.html index 60a18442..327681b0 100644 --- a/docs/api-en/symbols/src/docs_api-en_code_loader_LoadQueue.js.html +++ b/docs/api-en/symbols/src/docs_api-en_code_loader_LoadQueue.js.html @@ -91,147 +91,163 @@ 84 var item = this.get(id); 85 return item && item.content; 86 }, - 87 - 88 /** - 89 * start loading - 90 * @returns {LoadQueue} the loading instance - 91 */ - 92 start: function(){ - 93 var me = this; - 94 me._loadNext(); - 95 return me; - 96 }, - 97 - 98 /** - 99 * @private -100 */ -101 _loadNext: function(){ -102 var me = this, source = me._source, len = source.length; + 87 /** + 88 * remove resource object content by id or src + 89 * @param {String} specified id or src + 90 */ + 91 removeContent: function(id){ + 92 if(id){ + 93 var source = this._source; + 94 for(var i = 0; i < source.length; i++){ + 95 var item = source[i]; + 96 if(item.id === id || item.src === id){ + 97 source.splice(i, 1); + 98 return; + 99 } +100 } +101 } +102 }, 103 -104 //all items loaded -105 if(me._loaded >= len){ -106 me.fire('complete'); -107 return; -108 } -109 -110 if(me._currentIndex < len - 1 && me._connections < me.maxConnections){ -111 var index = ++me._currentIndex; -112 var item = source[index]; -113 var loader = me._getLoader(item); -114 -115 if(loader){ -116 var onLoad = loader.onLoad, onError = loader.onError; -117 -118 loader.onLoad = function(e){ -119 loader.onLoad = onLoad; -120 loader.onError = onError; -121 var content = onLoad && onLoad.call(loader, e) || e.target; -122 me._onItemLoad(index, content); -123 }; -124 loader.onError = function(e){ -125 loader.onLoad = onLoad; -126 loader.onError = onError; -127 onError && onError.call(loader, e); -128 me._onItemError(index, e); -129 }; -130 me._connections++; -131 } -132 -133 me._loadNext(); -134 loader && loader.load(item); -135 } -136 }, -137 -138 /** -139 * @private -140 */ -141 _getLoader: function(item){ -142 var loader = item.loader; -143 if(loader) return loader; -144 -145 var type = item.type || getExtension(item.src); -146 -147 switch(type){ -148 case 'png': -149 case 'jpg': -150 case 'jpeg': -151 case 'gif': -152 case 'webp': -153 loader = new ImageLoader(); -154 break; -155 case 'js': -156 case 'jsonp': -157 loader = new ScriptLoader(); -158 break; -159 } +104 /** +105 * start loading +106 * @returns {LoadQueue} the loading instance +107 */ +108 start: function(){ +109 var me = this; +110 me._loadNext(); +111 return me; +112 }, +113 +114 /** +115 * @private +116 */ +117 _loadNext: function(){ +118 var me = this, source = me._source, len = source.length; +119 +120 //all items loaded +121 if(me._loaded >= len){ +122 me.fire('complete'); +123 return; +124 } +125 +126 if(me._currentIndex < len - 1 && me._connections < me.maxConnections){ +127 var index = ++me._currentIndex; +128 var item = source[index]; +129 var loader = me._getLoader(item); +130 +131 if(loader){ +132 var onLoad = loader.onLoad, onError = loader.onError; +133 +134 loader.onLoad = function(e){ +135 loader.onLoad = onLoad; +136 loader.onError = onError; +137 var content = onLoad && onLoad.call(loader, e) || e.target; +138 me._onItemLoad(index, content); +139 }; +140 loader.onError = function(e){ +141 loader.onLoad = onLoad; +142 loader.onError = onError; +143 onError && onError.call(loader, e); +144 me._onItemError(index, e); +145 }; +146 me._connections++; +147 } +148 +149 me._loadNext(); +150 loader && loader.load(item); +151 } +152 }, +153 +154 /** +155 * @private +156 */ +157 _getLoader: function(item){ +158 var loader = item.loader; +159 if(loader) return loader; 160 -161 return loader; -162 }, -163 -164 /** -165 * @private -166 */ -167 _onItemLoad: function(index, content){ -168 var me = this, item = me._source[index]; -169 item.loaded = true; -170 item.content = content; -171 me._connections--; -172 me._loaded++; -173 me.fire('load', item); -174 me._loadNext(); -175 }, +161 var type = item.type || getExtension(item.src); +162 +163 switch(type){ +164 case 'png': +165 case 'jpg': +166 case 'jpeg': +167 case 'gif': +168 case 'webp': +169 loader = new ImageLoader(); +170 break; +171 case 'js': +172 case 'jsonp': +173 loader = new ScriptLoader(); +174 break; +175 } 176 -177 /** -178 * @private -179 */ -180 _onItemError: function(index, e){ -181 var me = this, item = me._source[index]; -182 item.error = e; -183 me._connections--; -184 me._loaded++; -185 me.fire('error', item); -186 me._loadNext(); -187 }, -188 -189 /** -190 * get resource size, loaded or all. -191 * @param {Boolean} identify loaded or all resource. default is false, return all resource size. when set true, return loaded resource size. -192 * @returns {Number} resource size. -193 */ -194 getSize: function(loaded){ -195 var size = 0, source = this._source; -196 for(var i = 0; i < source.length; i++){ -197 var item = source[i]; -198 size += (loaded ? item.loaded && item.size : item.size) || 0; -199 } -200 return size; -201 }, -202 -203 /** -204 * get loaded resource count -205 * @returns {Uint} loaded resource count -206 */ -207 getLoaded: function(){ -208 return this._loaded; -209 }, -210 -211 /** -212 * get all resource count -213 * @returns {Uint} all resource count -214 */ -215 getTotal: function(){ -216 return this._source.length; -217 } +177 return loader; +178 }, +179 +180 /** +181 * @private +182 */ +183 _onItemLoad: function(index, content){ +184 var me = this, item = me._source[index]; +185 item.loaded = true; +186 item.content = content; +187 me._connections--; +188 me._loaded++; +189 me.fire('load', item); +190 me._loadNext(); +191 }, +192 +193 /** +194 * @private +195 */ +196 _onItemError: function(index, e){ +197 var me = this, item = me._source[index]; +198 item.error = e; +199 me._connections--; +200 me._loaded++; +201 me.fire('error', item); +202 me._loadNext(); +203 }, +204 +205 /** +206 * get resource size, loaded or all. +207 * @param {Boolean} identify loaded or all resource. default is false, return all resource size. when set true, return loaded resource size. +208 * @returns {Number} resource size. +209 */ +210 getSize: function(loaded){ +211 var size = 0, source = this._source; +212 for(var i = 0; i < source.length; i++){ +213 var item = source[i]; +214 size += (loaded ? item.loaded && item.size : item.size) || 0; +215 } +216 return size; +217 }, 218 -219 }); -220 -221 /** -222 * @private -223 */ -224 function getExtension(src){ -225 var extRegExp = /\/?[^/]+\.(\w+)(\?\S+)?$/i, match, extension; -226 if(match = src.match(extRegExp)){ -227 extension = match[1].toLowerCase(); -228 } -229 return extension || null; -230 } \ No newline at end of file +219 /** +220 * get loaded resource count +221 * @returns {Uint} loaded resource count +222 */ +223 getLoaded: function(){ +224 return this._loaded; +225 }, +226 +227 /** +228 * get all resource count +229 * @returns {Uint} all resource count +230 */ +231 getTotal: function(){ +232 return this._source.length; +233 } +234 +235 }); +236 +237 /** +238 * @private +239 */ +240 function getExtension(src){ +241 var extRegExp = /\/?[^/]+\.(\w+)(\?\S+)?$/i, match, extension; +242 if(match = src.match(extRegExp)){ +243 extension = match[1].toLowerCase(); +244 } +245 return extension || null; +246 } \ No newline at end of file diff --git a/docs/api-zh/code/loader/LoadQueue.js b/docs/api-zh/code/loader/LoadQueue.js index edc23af6..1fa70954 100644 --- a/docs/api-zh/code/loader/LoadQueue.js +++ b/docs/api-zh/code/loader/LoadQueue.js @@ -84,6 +84,22 @@ var LoadQueue = Class.create(/** @lends LoadQueue.prototype */{ var item = this.get(id); return item && item.content; }, + /** + * 根据id或src地址删除资源内容。 + * @param {String} id 指定资源的id或src。 + */ + removeContent: function(id){ + if(id){ + var source = this._source; + for(var i = 0; i < source.length; i++){ + var item = source[i]; + if(item.id === id || item.src === id){ + source.splice(i, 1); + return; + } + } + } + }, /** * 开始下载队列。 diff --git a/docs/api-zh/index.html b/docs/api-zh/index.html index cf7ef42f..b9b46ebc 100644 --- a/docs/api-zh/index.html +++ b/docs/api-zh/index.html @@ -188,7 +188,7 @@
    -
    全部类概览(v1.5.0)
    +
    全部类概览(v1.6.0)
    diff --git a/docs/api-zh/symbols/LoadQueue.html b/docs/api-zh/symbols/LoadQueue.html index 53a7419d..ac997f76 100644 --- a/docs/api-zh/symbols/LoadQueue.html +++ b/docs/api-zh/symbols/LoadQueue.html @@ -486,6 +486,24 @@

    方法概览

    + + + + + + +
    + + +
    removeContent(id:String) +
    +
    + + 根据id或src地址删除资源内容。 +
    +
    + LoadQueue +
    @@ -926,6 +944,36 @@

    构造函数

    + + + +
    +
    + + removeContent(id:String) +
    +
    根据id或src地址删除资源内容。
    + + + + +
    +
    parameters
    + +
    + id:String + — 指定资源的id或src。 +
    + +
    + + + + + + + +
    diff --git a/docs/api-zh/symbols/src/docs_api-zh_code_loader_LoadQueue.js.html b/docs/api-zh/symbols/src/docs_api-zh_code_loader_LoadQueue.js.html index 8fe0e658..d9ae480c 100644 --- a/docs/api-zh/symbols/src/docs_api-zh_code_loader_LoadQueue.js.html +++ b/docs/api-zh/symbols/src/docs_api-zh_code_loader_LoadQueue.js.html @@ -91,147 +91,163 @@ 84 var item = this.get(id); 85 return item && item.content; 86 }, - 87 - 88 /** - 89 * 开始下载队列。 - 90 * @returns {LoadQueue} 下载队列实例本身。 - 91 */ - 92 start: function(){ - 93 var me = this; - 94 me._loadNext(); - 95 return me; - 96 }, - 97 - 98 /** - 99 * @private -100 */ -101 _loadNext: function(){ -102 var me = this, source = me._source, len = source.length; + 87 /** + 88 * 根据id或src地址删除资源内容。 + 89 * @param {String} id 指定资源的id或src。 + 90 */ + 91 removeContent: function(id){ + 92 if(id){ + 93 var source = this._source; + 94 for(var i = 0; i < source.length; i++){ + 95 var item = source[i]; + 96 if(item.id === id || item.src === id){ + 97 source.splice(i, 1); + 98 return; + 99 } +100 } +101 } +102 }, 103 -104 //all items loaded -105 if(me._loaded >= len){ -106 me.fire('complete'); -107 return; -108 } -109 -110 if(me._currentIndex < len - 1 && me._connections < me.maxConnections){ -111 var index = ++me._currentIndex; -112 var item = source[index]; -113 var loader = me._getLoader(item); -114 -115 if(loader){ -116 var onLoad = loader.onLoad, onError = loader.onError; -117 -118 loader.onLoad = function(e){ -119 loader.onLoad = onLoad; -120 loader.onError = onError; -121 var content = onLoad && onLoad.call(loader, e) || e.target; -122 me._onItemLoad(index, content); -123 }; -124 loader.onError = function(e){ -125 loader.onLoad = onLoad; -126 loader.onError = onError; -127 onError && onError.call(loader, e); -128 me._onItemError(index, e); -129 }; -130 me._connections++; -131 } -132 -133 me._loadNext(); -134 loader && loader.load(item); -135 } -136 }, -137 -138 /** -139 * @private -140 */ -141 _getLoader: function(item){ -142 var loader = item.loader; -143 if(loader) return loader; -144 -145 var type = item.type || getExtension(item.src); -146 -147 switch(type){ -148 case 'png': -149 case 'jpg': -150 case 'jpeg': -151 case 'gif': -152 case 'webp': -153 loader = new ImageLoader(); -154 break; -155 case 'js': -156 case 'jsonp': -157 loader = new ScriptLoader(); -158 break; -159 } +104 /** +105 * 开始下载队列。 +106 * @returns {LoadQueue} 下载队列实例本身。 +107 */ +108 start: function(){ +109 var me = this; +110 me._loadNext(); +111 return me; +112 }, +113 +114 /** +115 * @private +116 */ +117 _loadNext: function(){ +118 var me = this, source = me._source, len = source.length; +119 +120 //all items loaded +121 if(me._loaded >= len){ +122 me.fire('complete'); +123 return; +124 } +125 +126 if(me._currentIndex < len - 1 && me._connections < me.maxConnections){ +127 var index = ++me._currentIndex; +128 var item = source[index]; +129 var loader = me._getLoader(item); +130 +131 if(loader){ +132 var onLoad = loader.onLoad, onError = loader.onError; +133 +134 loader.onLoad = function(e){ +135 loader.onLoad = onLoad; +136 loader.onError = onError; +137 var content = onLoad && onLoad.call(loader, e) || e.target; +138 me._onItemLoad(index, content); +139 }; +140 loader.onError = function(e){ +141 loader.onLoad = onLoad; +142 loader.onError = onError; +143 onError && onError.call(loader, e); +144 me._onItemError(index, e); +145 }; +146 me._connections++; +147 } +148 +149 me._loadNext(); +150 loader && loader.load(item); +151 } +152 }, +153 +154 /** +155 * @private +156 */ +157 _getLoader: function(item){ +158 var loader = item.loader; +159 if(loader) return loader; 160 -161 return loader; -162 }, -163 -164 /** -165 * @private -166 */ -167 _onItemLoad: function(index, content){ -168 var me = this, item = me._source[index]; -169 item.loaded = true; -170 item.content = content; -171 me._connections--; -172 me._loaded++; -173 me.fire('load', item); -174 me._loadNext(); -175 }, +161 var type = item.type || getExtension(item.src); +162 +163 switch(type){ +164 case 'png': +165 case 'jpg': +166 case 'jpeg': +167 case 'gif': +168 case 'webp': +169 loader = new ImageLoader(); +170 break; +171 case 'js': +172 case 'jsonp': +173 loader = new ScriptLoader(); +174 break; +175 } 176 -177 /** -178 * @private -179 */ -180 _onItemError: function(index, e){ -181 var me = this, item = me._source[index]; -182 item.error = e; -183 me._connections--; -184 me._loaded++; -185 me.fire('error', item); -186 me._loadNext(); -187 }, -188 -189 /** -190 * 获取全部或已下载的资源的字节大小。 -191 * @param {Boolean} loaded 指示是已下载的资源还是全部资源。默认为全部。 -192 * @returns {Number} 指定资源的字节大小。 -193 */ -194 getSize: function(loaded){ -195 var size = 0, source = this._source; -196 for(var i = 0; i < source.length; i++){ -197 var item = source[i]; -198 size += (loaded ? item.loaded && item.size : item.size) || 0; -199 } -200 return size; -201 }, -202 -203 /** -204 * 获取已下载的资源数量。 -205 * @returns {Uint} 已下载的资源数量。 -206 */ -207 getLoaded: function(){ -208 return this._loaded; -209 }, -210 -211 /** -212 * 获取所有资源的数量。 -213 * @returns {Uint} 所有资源的数量。 -214 */ -215 getTotal: function(){ -216 return this._source.length; -217 } +177 return loader; +178 }, +179 +180 /** +181 * @private +182 */ +183 _onItemLoad: function(index, content){ +184 var me = this, item = me._source[index]; +185 item.loaded = true; +186 item.content = content; +187 me._connections--; +188 me._loaded++; +189 me.fire('load', item); +190 me._loadNext(); +191 }, +192 +193 /** +194 * @private +195 */ +196 _onItemError: function(index, e){ +197 var me = this, item = me._source[index]; +198 item.error = e; +199 me._connections--; +200 me._loaded++; +201 me.fire('error', item); +202 me._loadNext(); +203 }, +204 +205 /** +206 * 获取全部或已下载的资源的字节大小。 +207 * @param {Boolean} loaded 指示是已下载的资源还是全部资源。默认为全部。 +208 * @returns {Number} 指定资源的字节大小。 +209 */ +210 getSize: function(loaded){ +211 var size = 0, source = this._source; +212 for(var i = 0; i < source.length; i++){ +213 var item = source[i]; +214 size += (loaded ? item.loaded && item.size : item.size) || 0; +215 } +216 return size; +217 }, 218 -219 }); -220 -221 /** -222 * @private -223 */ -224 function getExtension(src){ -225 var extRegExp = /\/?[^/]+\.(\w+)(\?\S+)?$/i, match, extension; -226 if(match = src.match(extRegExp)){ -227 extension = match[1].toLowerCase(); -228 } -229 return extension || null; -230 } \ No newline at end of file +219 /** +220 * 获取已下载的资源数量。 +221 * @returns {Uint} 已下载的资源数量。 +222 */ +223 getLoaded: function(){ +224 return this._loaded; +225 }, +226 +227 /** +228 * 获取所有资源的数量。 +229 * @returns {Uint} 所有资源的数量。 +230 */ +231 getTotal: function(){ +232 return this._source.length; +233 } +234 +235 }); +236 +237 /** +238 * @private +239 */ +240 function getExtension(src){ +241 var extRegExp = /\/?[^/]+\.(\w+)(\?\S+)?$/i, match, extension; +242 if(match = src.match(extRegExp)){ +243 extension = match[1].toLowerCase(); +244 } +245 return extension || null; +246 } \ No newline at end of file diff --git a/package.json b/package.json index 5f208674..e328fda7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "Hilo", - "version": "1.5.0", + "version": "1.6.0", "description": "Hilo Game Framework", "author": "Hilo Dev Team", "license": "MIT",