//>>built
define("dojox/gfx/canvasWithEvents","dojo/_base/lang dojo/_base/declare dojo/has dojo/on dojo/aspect dojo/touch dojo/_base/Color dojo/dom dojo/dom-geometry dojo/_base/window ./_base ./canvas ./shape ./matrix".split(" "),function(w,m,u,x,E,G,F,B,C,H,y,q,I,z){function D(a){var b={},c;for(c in a)b[c]="function"===typeof a[c]?w.hitch(a,c):a[c];return b}u.add("dom-mutableEvents",function(){var a=document.createEvent("UIEvents");try{return Object.defineProperty?Object.defineProperty(a,"type",{value:"foo"}):
a.type="foo","foo"===a.type}catch(b){return!1}});var g=y.canvasWithEvents={};g.Shape=m("dojox.gfx.canvasWithEvents.Shape",q.Shape,{_testInputs:function(a,b){if(this.clip||!this.canvasFill&&this.strokeStyle)this._hitTestPixel(a,b);else{this._renderShape(a);for(var c=b.length,e=this.getTransform(),d=0;d<c;++d){var h=b[d];if(!h.target){var f=h.x,n=h.y;f=e?z.multiplyPoint(z.invert(e),f,n):{x:f,y:n};h.target=this._hitTestGeometry(a,f.x,f.y)}}}},_hitTestPixel:function(a,b){for(var c=0;c<b.length;++c){var e=
b[c];if(!e.target){var d=e.x,h=e.y;a.clearRect(0,0,1,1);a.save();a.translate(-d,-h);this._render(a,!0);e.target=a.getImageData(0,0,1,1).data[0]?this:null;a.restore()}}},_hitTestGeometry:function(a,b,c){return a.isPointInPath(b,c)?this:null},_renderFill:function(a,b){a.pickingMode?"canvasFill"in this&&b&&a.fill():this.inherited(arguments)},_renderStroke:function(a){if(this.strokeStyle&&a.pickingMode){var b=this.strokeStyle.color;try{this.strokeStyle.color=new F(a.strokeStyle),this.inherited(arguments)}finally{this.strokeStyle.color=
b}}else this.inherited(arguments)},getEventSource:function(){return this.surface.rawNode},on:function(a,b){var c=this.rawNode;return x(this.getEventSource(),a,function(e){B.isDescendant(e.target,c)&&b.apply(c,arguments)})},connect:function(a,b,c){"on"==a.substring(0,2)&&(a=a.substring(2));return this.on(a,c?w.hitch(b,c):w.hitch(null,b))},disconnect:function(a){a.remove()}});g.Group=m("dojox.gfx.canvasWithEvents.Group",[g.Shape,q.Group],{_testInputs:function(a,b){var c=this.children,e=this.getTransform(),
d;if(0!==c.length){var h=[];for(d=0;d<b.length;++d){var f=b[d];h[d]={x:f.x,y:f.y};if(!f.target){var n=f.x,p=f.y;n=e?z.multiplyPoint(z.invert(e),n,p):{x:n,y:p};f.x=n.x;f.y=n.y}}for(d=c.length-1;0<=d;--d){c[d]._testInputs(a,b);f=!0;for(e=0;e<b.length;++e)if(null==b[e].target){f=!1;break}if(f)break}if(this.clip)for(d=0;d<b.length;++d)f=b[d],f.x=h[d].x,f.y=h[d].y,f.target&&(a.clearRect(0,0,1,1),a.save(),a.translate(-f.x,-f.y),this._render(a,!0),a.getImageData(0,0,1,1).data[0]||(f.target=null),a.restore());
else for(d=0;d<b.length;++d)b[d].x=h[d].x,b[d].y=h[d].y}}});g.Image=m("dojox.gfx.canvasWithEvents.Image",[g.Shape,q.Image],{_renderShape:function(a){var b=this.shape;a.pickingMode?a.fillRect(b.x,b.y,b.width,b.height):this.inherited(arguments)},_hitTestGeometry:function(a,b,c){a=this.shape;return b>=a.x&&b<=a.x+a.width&&c>=a.y&&c<=a.y+a.height?this:null}});g.Text=m("dojox.gfx.canvasWithEvents.Text",[g.Shape,q.Text],{_testInputs:function(a,b){return this._hitTestPixel(a,b)}});g.Rect=m("dojox.gfx.canvasWithEvents.Rect",
[g.Shape,q.Rect],{});g.Circle=m("dojox.gfx.canvasWithEvents.Circle",[g.Shape,q.Circle],{});g.Ellipse=m("dojox.gfx.canvasWithEvents.Ellipse",[g.Shape,q.Ellipse],{});g.Line=m("dojox.gfx.canvasWithEvents.Line",[g.Shape,q.Line],{});g.Polyline=m("dojox.gfx.canvasWithEvents.Polyline",[g.Shape,q.Polyline],{});g.Path=m("dojox.gfx.canvasWithEvents.Path",[g.Shape,q.Path],{});g.TextPath=m("dojox.gfx.canvasWithEvents.TextPath",[g.Shape,q.TextPath],{});var v=null;g.Surface=m("dojox.gfx.canvasWithEvents.Surface",
q.Surface,{constructor:function(){this._elementUnderPointer=null},fixTarget:function(a){var b=this;return function(c){var e;if(v)if(u("dom-mutableEvents"))Object.defineProperties(c,v);else for(e in c=D(c),v)c[e]=v[e].value;else{var d=b.getEventSource()._dojoElementFromPoint((c.changedTouches?c.changedTouches[0]:c).pageX,(c.changedTouches?c.changedTouches[0]:c).pageY);u("dom-mutableEvents")?Object.defineProperties(c,{target:{value:d,configurable:!0,enumerable:!0},gfxTarget:{value:d.shape,configurable:!0,
enumerable:!0}}):(c=D(c),c.target=d,c.gfxTarget=d.shape)}if(u("touch")){if(c.changedTouches&&c.changedTouches[0])for(e in d=c.changedTouches[0],d)c[e]||(u("dom-mutableEvents")?Object.defineProperty(c,e,{value:d[e],configurable:!0,enumerable:!0}):c[e]=d[e]);c.corrected=c}return a.call(this,c)}},_checkPointer:function(a){function b(n,p,t){for(var l=a.bubbles,k=0,r;r=n[k];++k)v={target:{value:p,configurable:!0,enumerable:!0},gfxTarget:{value:p.shape,configurable:!0,enumerable:!0},relatedTarget:{value:t,
configurable:!0,enumerable:!0}},Object.defineProperty(a,"bubbles",{value:r.bubbles,configurable:!0,enumerable:!0}),x.emit(f,r.type,a),v=null;Object.defineProperty(a,"bubbles",{value:l,configurable:!0,enumerable:!0})}var c=[{type:"mouseout",bubbles:!0},{type:"MSPointerOut",bubbles:!0},{type:"pointerout",bubbles:!0},{type:"mouseleave",bubbles:!1},{type:"dojotouchout",bubbles:!0}],e=[{type:"mouseover",bubbles:!0},{type:"MSPointerOver",bubbles:!0},{type:"pointerover",bubbles:!0},{type:"mouseenter",bubbles:!1},
{type:"dojotouchover",bubbles:!0}],d=a.target,h=this._elementUnderPointer,f=this.getEventSource();h!==d&&(h&&h!==f&&b(c,h,d),(this._elementUnderPointer=d)&&d!==f&&b(e,d,h))},getEventSource:function(){return this.rawNode},on:function(a,b){return x(this.getEventSource(),a,b)},connect:function(a,b,c){"on"==a.substring(0,2)&&(a=a.substring(2));return this.on(a,c?w.hitch(b,c):b)},disconnect:function(a){a.remove()},_initMirrorCanvas:function(){this._initMirrorCanvas=function(){};var a=this.getEventSource(),
b=this.mirrorCanvas=a.ownerDocument.createElement("canvas");b.width=1;b.height=1;b.style.position="absolute";b.style.left=b.style.top="-99999px";a.parentNode.appendChild(b);b="mousemove";u("pointer-events")?b="pointermove":u("MSPointer")?b="MSPointerMove":u("touch-events")&&(b="touchmove");x(a,b,w.hitch(this,"_checkPointer"))},destroy:function(){this.mirrorCanvas&&(this.mirrorCanvas.parentNode.removeChild(this.mirrorCanvas),this.mirrorCanvas=null);this.inherited(arguments)}});g.createSurface=function(a,
b,c){if(!b&&!c){var e=C.position(a);b=b||e.w;c=c||e.h}"number"===typeof b&&(b+="px");"number"===typeof c&&(c+="px");var d=new g.Surface;e=B.byId(a);a=e.ownerDocument.createElement("canvas");a.width=y.normalizedLength(b);a.height=y.normalizedLength(c);e.appendChild(a);d.rawNode=a;d._parent=e;d.surface=d;y._base._fixMsTouchAction(d);var h=a.addEventListener,f=a.removeEventListener,n=[];b=function(p,t,l){d._initMirrorCanvas();var k=d.fixTarget(t);n.push({original:t,actual:k});h.call(this,p,k,l)};c=function(p,
t,l){for(var k=0,r;r=n[k];++k)if(r.original===t){f.call(this,p,r.actual,l);n.splice(k,1);break}};try{Object.defineProperties(a,{addEventListener:{value:b,enumerable:!0,configurable:!0},removeEventListener:{value:c}})}catch(p){a.addEventListener=b,a.removeEventListener=c}a._dojoElementFromPoint=function(p,t){if(!d.mirrorCanvas)return this;var l=C.position(this,!0);p-=l.x;t-=l.y;var k=d.mirrorCanvas;l=k.getContext("2d");var r=d.children;l.clearRect(0,0,k.width,k.height);l.save();l.strokeStyle="rgba(127,127,127,1.0)";
l.fillStyle="rgba(127,127,127,1.0)";l.pickingMode=!0;k=[{x:p,y:t}];for(var A=r.length-1;0<=A&&(r[A]._testInputs(l,k),!k[0].target);A--);l.restore();return k[0]&&k[0].target?k[0].target.rawNode:this};return d};m={createObject:function(){var a=this.inherited(arguments),b={};a.rawNode={shape:a,ownerDocument:a.surface.rawNode.ownerDocument,parentNode:a.parent?a.parent.rawNode:null,addEventListener:function(c,e){for(var d=b[c]=b[c]||[],h=0,f;f=d[h];++h)if(f.listener===e)return;d.push({listener:e,handle:E.after(this,
"on"+c,a.surface.fixTarget(e),!0)})},removeEventListener:function(c,e){var d=b[c];if(d)for(var h=0,f;f=d[h];++h)if(f.listener===e){f.handle.remove();d.splice(h,1);break}}};return a}};g.Group.extend(m);g.Surface.extend(m);return g});