//>>built define(["dojo","dijit/registry","../util/oo","../manager/_registry","../stencil/Text"],function(d,q,n,r,t){var h;d.addOnLoad(function(){(h=d.byId("conEdit"))?h.parentNode.removeChild(h):console.error("A contenteditable div is missing from the main document. See 'dojox.drawing.tools.TextBlock'")});n=n.declare(t,function(a){if(a.data){a=a.data;var c=a.text?this.typesetter(a.text):a.text,b=a.width?"auto"==a.width?"auto":Math.max(a.width,this.style.text.minWidth):this.style.text.minWidth,e=this._lineHeight; c&&"auto"==b?(e=this.measureText(this.cleanText(c,!1),b),b=e.w,e=e.h):this._text="";this.points=[{x:a.x,y:a.y},{x:a.x+b,y:a.y},{x:a.x+b,y:a.y+e},{x:a.x,y:a.y+e}];a.showEmpty||c?(this.editMode=!0,d.disconnect(this._postRenderCon),this._postRenderCon=null,this.connect(this,"render",this,"onRender",!0),a.showEmpty?(this._text=c||"",this.edit()):c&&a.editMode?(this._text="",this.edit()):c&&this.render(c),setTimeout(d.hitch(this,function(){this.editMode=!1}),100)):this.render()}else this.connectMouse(), this._postRenderCon=d.connect(this,"render",this,"_onPostRender")},{draws:!0,baseRender:!1,type:"dojox.drawing.tools.TextBlock",_caretStart:0,_caretEnd:0,_blockExec:!1,selectOnExec:!0,showEmpty:!1,onDrag:function(a){this.parentNode||this.showParent(a);var c=this._startdrag;a=a.page;this._box.left=c.xd.trim(h.innerHTML).length&&l&&(d.style(h,"height",this._lineHeight+"px"),l=!1);if(this._blockExec)b.keyCode==d.keys.SPACE&&(d.stopEvent(b),c&&a.onCancel());else if(13==b.keyCode||27==b.keyCode)d.stopEvent(b),m()});e=d.connect(h,"keydown",this,function(b){13!=b.keyCode&&27!=b.keyCode||d.stopEvent(b);if(220==b.keyCode){if(!c){console.info("For greek letter assistance instantiate: dojox.drawing.plugins.drawing.GreekPalette"); return}d.stopEvent(b);this.getSelection(h);this.insertText(h,"\\");this._blockExec=this._dropMode=!0;a.show({around:this.parentNode,orient:{BL:"TL"}})}if(this._dropMode)switch(b.keyCode){case d.keys.UP_ARROW:case d.keys.DOWN_ARROW:case d.keys.LEFT_ARROW:case d.keys.RIGHT_ARROW:d.stopEvent(b);a._navigateByArrow(b);break;case d.keys.ENTER:d.stopEvent(b);a._onCellClick(b);break;case d.keys.BACKSPACE:case d.keys.DELETE:d.stopEvent(b),a.onCancel()}else this._blockExec=!1});f=d.connect(document,"mouseup", this,function(a){this._onAnchor||"conEdit"==a.target.id?"conEdit"==a.target.id&&""==h.innerHTML&&(h.blur(),setTimeout(function(){h.focus()},200)):(d.stopEvent(a),m())});this.createAnchors();g=d.connect(this.mouse,"setZoom",this,function(a){m()});h.focus();this.onDown=function(){};this.onDrag=function(){};setTimeout(d.hitch(this,function(){h.focus();this.onUp=function(){!k._onAnchor&&this.parentNode&&(k.disconnectMouse(),m(),k.onUp=function(){})}}),500)}},execText:function(){var a=d.marginBox(this.parentNode), a=Math.max(a.w,this.style.text.minWidth),c=this.cleanText(h.innerHTML,!0);h.innerHTML="";h.blur();this.destroyAnchors();var c=this.typesetter(c),c=this.measureText(c,a),b=this.mouse.scrollOffset(),e=this.mouse.origin,f=this._box.left+b.left-e.x,b=this._box.top+b.top-e.y,f=f*this.mouse.zoom,b=b*this.mouse.zoom,a=a*this.mouse.zoom;c.h*=this.mouse.zoom;this.points=[{x:f,y:b},{x:f+a,y:b},{x:f+a,y:b+c.h},{x:f,y:b+c.h}];this.editMode=!1;console.log("EXEC TEXT::::",this._postRenderCon);c.text||(this._text= "",this._textArray=[]);this.render(c.text);this.onChangeText(this.getText())},edit:function(){this.editMode=!0;var a=this.getText()||"";console.log("EDIT TEXT:",a," ",a.replace("/n"," "));if(!this.parentNode&&this.points){var c=this.pointsToData(),b=this.mouse.scrollOffset(),d=this.mouse.origin,c={pageX:c.x/this.mouse.zoom-b.left+d.x,pageY:c.y/this.mouse.zoom-b.top+d.y,width:c.width/this.mouse.zoom,height:c.height/this.mouse.zoom};this.remove(this.shape,this.hit);this.showParent(c);this.createTextField(a.replace("/n", " "));this.connectTextField();a&&this.setSelection(h,"end")}},cleanText:function(a,c){c&&d.forEach(["\x3cbr\x3e","\x3cbr/\x3e","\x3cbr /\x3e","\\n","\\r"],function(b){a=a.replace(new RegExp(b,"gi")," ")});a=a.replace(/ /g," ");a=function(a){var b={"\x26lt;":"\x3c","\x26gt;":"\x3e","\x26amp;":"\x26"},c;for(c in b)a=a.replace(new RegExp(c,"gi"),b[c]);return a}(a);a=d.trim(a);return a=a.replace(/\s{2,}/g," ")},measureText:function(a,c){this.showParent({width:c||"auto",height:"auto"});this.createTextField(a); var b="",e=h;e.innerHTML="X";b=d.marginBox(e).h;e.innerHTML=a;if(!c||/()|(\n)|(\r)/gi.test(a))b=a.replace(/()|(\n)|(\r)/gi,"\n"),e.innerHTML=a.replace(/()|(\n)|(\r)/gi,"\x3cbr/\x3e");else if(d.marginBox(e).h==b)b=a;else{a=a.split(" ");var f=[[]];c=0;for(e.innerHTML="";a.length;){var g=a.shift();e.innerHTML+=g+" ";d.marginBox(e).h>b&&(c++,f[c]=[],e.innerHTML=g+" ");f[c].push(g)}d.forEach(f,function(a,b){f[b]=a.join(" ")});b=f.join("\n");e.innerHTML=b.replace("\n","\x3cbr/\x3e")}e= d.marginBox(e);h.parentNode.removeChild(h);d.destroy(this.parentNode);this.parentNode=null;return{h:e.h,w:e.w,text:b}},_downOnCanvas:!1,onDown:function(a){this._startdrag={x:a.pageX,y:a.pageY};d.disconnect(this._postRenderCon);this._postRenderCon=null;this._downOnCanvas=!0},createAnchors:function(){this._anchors={};var a=this,c=this.style.anchors,b=c.width,e=c.size-2*b,f=c.size/2*-1+"px",c={position:"absolute",width:e+"px",height:c.size-2*b+"px",backgroundColor:c.fill,border:b+"px "+c.style+" "+c.color}; d.isIE&&(c.paddingLeft=e+"px",c.fontSize=e+"px");e=[{top:f,left:f},{top:f,right:f},{bottom:f,right:f},{bottom:f,left:f}];for(f=0;4>f;f++){var g=0==f||3==f,b=this.util.uid(g?"left_anchor":"right_anchor"),k=d.create("div",{id:b},this.parentNode);d.style(k,d.mixin(d.clone(c),e[f]));var l,m,p;l=d.connect(k,"mousedown",this,function(b){g=-1