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