{"size": 18443, "ext": "js", "max_stars_repo_path": "www/html/bitrix/modules/main/install/js/main/core/core_canvas.min.js", "max_stars_repo_name": "Evil1991/bitrixdock", "max_stars_repo_stars_event_min_datetime": "2020-10-05T04:28:40.000Z", "max_stars_repo_stars_event_max_datetime": "2020-10-05T04:28:40.000Z", "max_issues_repo_path": "www/html/bitrix/modules/main/install/js/main/core/core_canvas.min.js", "max_issues_repo_name": "Evil1991/bitrixdock", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "www/html/bitrix/modules/main/install/js/main/core/core_canvas.min.js", "max_forks_repo_name": "Evil1991/bitrixdock", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 9221.5, "max_line_length": 18403, "alphanum_fraction": 0.7250447324}
(function(t){if(t.BX["CanvasEditor"])return false;var i=t.BX,e={},s=function(t,i){i=i||{};var e,s,a=[],n=t.elements.length,o=0,h=0;if(!!t){for(e=0;e<n;e++){var r=t.elements[e];if(r.disabled)continue;switch(r.type.toLowerCase()){case"text":case"textarea":case"password":case"hidden":case"select-one":a.push({name:r.name,value:r.value});h+=r.name.length+r.value.length;break;case"file":if(!!r.files){for(s=0;s<r.files.length;s++){o++;a.push({name:r.name,value:r.files[s]});h+=r.files[s].size}}break;case"radio":case"checkbox":if(r.checked){a.push({name:r.name,value:r.value});h+=r.name.length+r.value.length}break;case"select-multiple":for(var p=0;p<r.options.length;p++){if(r.options[p].selected){a.push({name:r.name,value:r.options[p].value});h+=r.name.length+r.options[p].length}}break;default:break}}e=0;h=0;var c=i;while(e<a.length){var d=a[e].name.indexOf("[");if(d==-1){c[a[e].name]=a[e].value;c=i;e++}else{var l=a[e].name.substring(0,d);var u=a[e].name.substring(d+1);if(!c[l])c[l]=[];var v=u.indexOf("]");if(v==-1){c=i;e++}else if(v==0){c=c[l];a[e].name=""+c.length}else{c=c[l];a[e].name=u.substring(0,v)+u.substring(v+1)}}}}return{data:i,filesCount:o,roughSize:h}};i.CanvasEditor=function(t){this.previewSize={width:1024,height:860,minWidth:500,minHeight:335};this.dialogName="BX.CanvasEditor";this.id=t+"Editor";this.canvas=new i.Canvas;i.addCustomEvent(this.canvas,"onChangeSize",i.delegate(function(t,e){var s=t.props,a={width:parseInt(t.style.width.replace("px","")),height:parseInt(t.style.height.replace("px",""))},n=i.pos(this.canvas.getCanvas().parentNode.parentNode),o={style:t.style},h,r=0,p=this.canvas.getCanvas();if(e==true){if(a.height>n.height||a.width>n.width){h=i.UploaderUtils.scaleImage(s,n,"inscribed");r=h.coeff;if(!p.hasAttribute("bx-bxu-html-compression-ratio-real"))p.setAttribute("bx-bxu-html-compression-ratio-real",p.getAttribute("bx-bxu-html-compression-ratio"));p.setAttribute("bx-bxu-html-compression-ratio",r)}else if(p.hasAttribute("bx-bxu-html-compression-ratio-real")){r=p.getAttribute("bx-bxu-html-compression-ratio-real");p.setAttribute("bx-bxu-html-compression-ratio",r);p.removeAttribute("bx-bxu-html-compression-ratio-real")}if(r>0)return this.canvas.setProps(s,false)}var c=Math.ceil((n.height-a.height)/2),d=Math.ceil((n.width-a.width)/2),l=n.width-d-a.width,u={style:{paddingTop:c+"px",paddingBottom:n.height-c-a.height+"px",paddingLeft:d+"px",paddingRight:l+"px"}};i.adjust(this.canvas.getCanvas().parentNode,o);i.adjust(this.canvas.getCanvas().parentNode.parentNode,u)},this));i.addCustomEvent(this.canvas,"onChangeCanvas",i.delegate(function(t){this.canvas.getCanvas().removeAttribute("bx-bxu-html-compression-ratio-real");var e=t.destin,s={},a=Math.max(e.width,this.previewSize.minWidth),n=Math.max(e.height,this.previewSize.minHeight);s.left=Math.ceil((a-e.width)/2);s.right=a-s.left-e.width;s.top=Math.ceil((n-e.height)/2);s.bottom=n-s.top-e.height;i.adjust(this.canvas.getCanvas().parentNode.parentNode,{style:{padding:""+s.top+"px "+s.right+"px "+s.bottom+"px "+s.left+"px"}})},this));this.popup=null;return this};i.CanvasEditor.prototype={onApply:function(){this.canvas.apply();i.onCustomEvent(this,"onApplyCanvas",[this.canvas.orig,s(i(this.id+"params"))])},onCancel:function(){i.onCustomEvent(this,"onCancelCanvas",[this.canvas.orig])},onDelete:function(){i.onCustomEvent(this,"onDeleteCanvas",[this.canvas.orig])},showEditor:function(t,e){e=!!e&&typeof e=="object"?e:{template:e};i.onCustomEvent(this,"onBeforeShow");var s=i.GetWindowInnerSize();if(s.innerWidth<this.previewSize.width)this.previewSize.width=s.innerWidth;if(s.innerHeight*.8<this.previewSize.height)this.previewSize.height=s.innerHeight*.8;if(this.popup===null){var a=i.UploaderUtils.scaleImage(t,this.previewSize,"inscribed");var n=i.create("DIV",{attrs:{id:this.id+"Proper",className:"bxu-edit-popup"},style:{display:"none"},html:['<div class="bxu-edit-top"> 							<span class="bxu-edit-name" id="',this.id,'title">',i.util.htmlspecialchars(e["title"]),'</span> 							<span class="bxu-edit-cls" id="',this.id,'close"></span> 						</div> 						<div class="bxu-edit-img-wrap">							<div class="bxu-edit-img-wrap-in" style="position:relative; margin:0;padding:0;border:none;"> 								<div style="position:relative; margin:0;padding:0;border:none;"> 									<canvas id="',this.id,'canvas" width="',a.destin.width,'" height="',a.destin.height,'"><canvas> 								</div> 							</div> 						</div> 						<div class="bxu-edit-btn-block"> 							<div class="bxu-edit-btn-wrap"> 								<span class="bxu-edit-btn bxu-edit-btn-turn-l" id="',this.id,"turn-l",'" title="',i.message("CANVAS_TURN_L"),'"> 									<span class="bxu-edit-btn-icon"></span> 								</span> 								<span class="bxu-edit-btn bxu-edit-btn-turn-r" id="',this.id,"turn-r",'"title="',i.message("CANVAS_TURN_R"),'"> 									<span class="bxu-edit-btn-icon"></span> 								</span> 								<span class="bxu-edit-btn bxu-edit-btn-flip-v" id="',this.id,"flip-v",'" title="',i.message("CANVAS_FLIP_V"),'"> 									<span class="bxu-edit-btn-icon"></span> 								</span> 								<span class="bxu-edit-btn bxu-edit-btn-flip-h" id="',this.id,"flip-h",'" title="',i.message("CANVAS_FLIP_H"),'"> 									<span class="bxu-edit-btn-icon"></span> 								</span> 								<span class="bxu-edit-btn bxu-edit-btn-crop" id="',this.id,"crop",'" title="',i.message("CANVAS_CROP"),'"> 									<span class="bxu-edit-btn-icon"></span> 								</span> 								<span class="bxu-edit-btn bxu-edit-btn-grayscale" id="',this.id,"grayscale",'" title="',i.message("CANVAS_GRAYSCALE"),'"> 									<span class="bxu-edit-btn-icon"></span> 								</span> 								<span class="bxu-edit-btn bxu-edit-btn-sign" id="',this.id,"sign",'" title="',i.message("CANVAS_SIGN"),'"> 									<span class="bxu-edit-btn-icon"></span> 								</span> 							</div> 							<div class="bxu-edit-inp-wrap"> 								<form onsubmit="return false;" id="',this.id,'params">',e["template"]||"","</form> 							</div> 						</div>"].join("")});var o=i.delegate(function(){i(this.id+"canvas").parentNode.replaceChild(this.canvas.cnv,i(this.id+"canvas"));i.bind(i(this.id+"turn-l"),"click",i.proxy(function(){this.rotate(false)},this.canvas));i.bind(i(this.id+"turn-r"),"click",i.proxy(function(){this.rotate(true)},this.canvas));i.bind(i(this.id+"flip-v"),"click",i.proxy(function(){this.flip(false)},this.canvas));i.bind(i(this.id+"flip-h"),"click",i.proxy(function(){this.flip(true)},this.canvas));i.bind(i(this.id+"crop"),"click",i.proxy(function(){this.crop(i.proxy_context)},this.canvas));i.bind(i(this.id+"grayscale"),"click",i.proxy(function(){this.blackAndWhite()},this.canvas));i.bind(i(this.id+"sign"),"click",i.proxy(function(){this.poster(i.proxy_context)},this.canvas));i.bind(i(this.id+"close"),"click",i.proxy(this.popup.close,this.popup));i.bind(i(this.id+"params"),"submit",i.proxy(this.onApply,this));i.removeCustomEvent(this.popup,"onPopupShow",o)},this),h=i.delegate(this.onCancel,this);this.popup=i.PopupWindowManager.create("popup"+this.id,null,{className:"bxu-popup",autoHide:false,lightShadow:true,closeIcon:false,closeByEsc:true,zIndex:1,content:n,overlay:{},events:{onPopupClose:i.delegate(function(){i.onCustomEvent(this,"onClose",[this]);this.canvas.reset()},this)},buttons:[new i.PopupWindowButton({text:i.message("CANVAS_OK"),className:"",events:{click:i.delegate(function(){this.onApply();i.removeCustomEvent(this.popup,"onPopupClose",h);this.popup.close()},this)}}),new i.PopupWindowButton({text:i.message("CANVAS_CANCEL"),className:"",events:{click:i.delegate(function(){this.popup.close()},this)}})]});i.addCustomEvent(this.popup,"onPopupShow",o);i.addCustomEvent(this.popup,"onPopupClose",h)}var r=i.delegate(function(){if(t!=null)this.copyCanvas(t);i(this.id+"params").innerHTML=e["template"]||"";if(!!e["template"]){i.defer_proxy(function(){var t=i(this.id+"params");if(!!t){for(var e=0;e<t.elements.length;e++){if(t.elements[e].type.toUpperCase()=="TEXT"||t.elements[e].tagName.toUpperCase()=="TEXTAREA"){i.focus(t.elements[e]);break}}}},this)()}i(this.id+"title").innerHTML=i.util.htmlspecialchars(e["title"]||"");i.removeCustomEvent(this.popup,"onAfterPopupShow",r)},this);i.addCustomEvent(this.popup,"onAfterPopupShow",r);this.popup.show();this.popup.adjustPosition();i.onCustomEvent(this,"onAfterShow");return true},copyCanvas:function(t){this.canvas.copy(t,this.previewSize)}};i.CanvasEditor.show=function(t,s,a){var n="";if(typeof a=="string")n=a;else if(typeof a=="object")n=a["id"];n=typeof n==="string"&&n.length>0?n:"default";if(!e[n])e[n]=new i.CanvasEditor(n);e[n].showEditor(t,s,a);return e[n]};i.CanvasEditor.replaceCanvas=function(t,i){i=typeof i==="string"&&i.length>0?i:"default";if(!!e[i])e[i].copyCanvas(t)};i.Canvas=function(){this.cnv=null;this.ctx=null;this.init();return this};i.Canvas.prototype={getVisFromReal:function(t){var i=this.cnv.getAttribute("bx-bxu-html-compression-ratio");return 0<i&&i<1?parseInt(i*t):t},getRealFromVis:function(t){var i=this.cnv.getAttribute("bx-bxu-html-compression-ratio");return 0<i&&i<1?parseInt(t/i):t},setStyles:function(t){var e={width:this.getRealFromVis(t.width),height:this.getRealFromVis(t.height)},s={width:t.width+"px",height:t.height+"px"};i.adjust(this.cnv,{props:e,style:s});i.onCustomEvent(this,"onChangeSize",[{props:e,style:s}])},setProps:function(t,e){var s={width:t.width,height:t.height},a={width:this.getVisFromReal(t.width)+"px",height:this.getVisFromReal(t.height)+"px"};i.adjust(this.cnv,{props:s,style:a});i.onCustomEvent(this,"onChangeSize",[{props:s,style:a},e])},getCanvas:function(){return this.cnv},init:function(){this.cnv=i.create("CANVAS");i.adjust(this.cnv,{width:100,height:100});this.ctx=this.cnv.getContext("2d");this.initDnD();return this.cnv},reset:function(){this.ctx.clearRect(0,0,this.cnv.width,this.cnv.height);i.adjust(this.cnv,{width:100,height:100})},apply:function(){this.orig.width=this.cnv.width;this.orig.height=this.cnv.height;this.orig.ctx=this.orig.getContext("2d");this.orig.ctx.drawImage(this.cnv,0,0)},copy:function(t,e){this.orig=t;e=e||{};e.width=e.width>0?e.width:0;e.height=e.height>0?e.height:0;var s=i.UploaderUtils.scaleImage(t,e,"inscribed");this.cnv.setAttribute("bx-bxu-html-compression-ratio",s.coeff);this.setProps(t);i.onCustomEvent(this,"onChangeCanvas",[s]);this.ctx=this.cnv.getContext("2d");this.ctx.drawImage(t,0,0);return this.cnv},poster:function(t){if(!!this.posterPopup)this.posterPopup.close();var e=i.pos(t);this.posterPopup=new i.PopupWindow("bx-poster-popup-"+t.id,t,{lightShadow:true,offsetTop:-3,className:"bxu-poster-popup",offsetLeft:Math.ceil(e.width/2),autoHide:true,closeByEsc:true,zIndex:i.PopupWindow.defaultOptions.popupOverlayZindex-i.PopupWindow.defaultOptions.popupZindex+2,bindOptions:{position:"top"},overlay:false,events:{onPopupClose:function(){this.destroy()},onPopupDestroy:i.proxy(function(){this.posterPopup=null},this)},buttons:[new i.PopupWindowButton({text:i.message("CANVAS_OK"),events:{click:i.delegate(function(){var e=i("posterPopupText"+t.id);if(!!e&&e.value.length>0)this.posterApply(e.value);this.posterPopup.close()},this)}}),new i.PopupWindowButton({text:i.message("CANVAS_CANCEL"),events:{click:i.delegate(function(){this.posterPopup.close()},this)}})],content:['<div class="bxu-poster-popup-dt">',i.message("CANVAS_POSTER_SIGN"),'</div> 					<input type="text" id="posterPopupText',t.id,'" maxlength="255" value="" />'].join("")});this.posterPopup.show();this.posterPopup.setAngle({position:"bottom"});this.posterPopup.bindOptions.forceBindPosition=true;this.posterPopup.adjustPosition();i.focus(i("posterPopupText"+t.id));this.posterPopup.bindOptions.forceBindPosition=false},posterApply:function(t){if(t){var i=Math.min(this.cnv.width,this.cnv.height)/10;this.ctx.fillStyle="black";this.ctx.fillRect(0,0,this.cnv.width,i);this.ctx.fillRect(0,this.cnv.height-2*i,this.cnv.width,2*i);this.ctx.fillRect(0,0,i,this.cnv.height);this.ctx.fillRect(this.cnv.width-i,0,i,this.cnv.height);this.ctx.strokeStyle="white";var e=5;this.ctx.strokeRect(i-e,i-e,this.cnv.width-i*2+2*e,this.cnv.height-i*3+2*e);this.ctx.fillStyle="white";this.ctx.textAlign="center";this.ctx.textBaseline="middle";this.ctx.font=i+"px marketing";this.ctx.fillText(t,this.cnv.width/2,this.cnv.height-i,this.cnv.width)}},blackAndWhite:function(){var t=this.ctx.getImageData(0,0,this.cnv.width,this.cnv.height),i,e;for(e=0;e<t.data.length;e+=4){i=(t.data[e]+t.data[e+1]+t.data[e+2])/3;t.data[e]=i;t.data[e+1]=i;t.data[e+2]=i}this.ctx.putImageData(t,0,0)},flip:function(t){this.ctx.save();if(t){this.ctx.scale(1,-1);this.ctx.translate(0,-this.cnv.height)}else{this.ctx.scale(-1,1);this.ctx.translate(-this.cnv.width,0)}this.ctx.drawImage(this.cnv,0,0);this.ctx.restore()},rotate:function(t){this.turn(this.cnv,this.ctx,t)},turn:function(t,e,s){var a=i.create("CANVAS",{props:{width:t.width,height:t.height},style:{display:"none"}});a.getContext("2d").drawImage(t,0,0);this.setProps({width:a.height,height:a.width},true);e.save();if(s)e.translate(this.cnv.width,0);else e.translate(0,this.cnv.height);var n=Math.PI/2*(s?1:-1);e.rotate(n);e.drawImage(a,0,0);e.restore();a=null},resize:function(t){var e=i.create("CANVAS",{props:{width:this.cnv.width,height:this.cnv.height},style:{display:"none"}});e.getContext("2d").drawImage(this.cnv,0,0);this.cnv.width*=t;this.cnv.height*=t;this.ctx.save();this.ctx.scale(t,t);this.ctx.drawImage(e,0,0);this.ctx.restore();e=null},_imageDropped:function(t,e,s,a){var n=i.create("IMG",{style:{display:"none"},events:{load:i.delegate(function(){var t=n.width>this.cnv.width/3?this.cnv.width/3/n.width:1,i=n.height>this.cnv.height/3?this.cnv.height/3/n.height:1,o=Math.min(t,i);this.cnv.save();this.cnv.translate(e-n.width*o/2,s-n.height*o/2);this.cnv.scale(o,o);this.cnv.drawImage(n,0,0);if(a){this.cnv.strokeStyle="white";this.cnv.lineWidth=5/o;this.cnv.strokeRect(0,0,n.width,n.height)}this.cnv.restore();document.body.removeChild(n);n=null},this)}});n.src=t;document.body.appendChild(n)},initDnD:function(){if(!!i.DD&&i.type.isDomNode(this.cnv)&&this.cnv.parentNode){this.cnvDD=new i.DD.dropFiles(this.cnv.canvas);if(this.cnvDD&&this.cnvDD.supported()&&i.ajax.FormData.isSupported()){i.addCustomEvent(this.cnvDD,"dragover",i.preventDefault);i.addCustomEvent(this.cnvDD,"drop",i.delegate(function(t){i.preventDefault(t);i.fixEventPageXY(t);var e=t.dataTransfer,s=t.pageX-this.cnv.canvas.offsetLeft-this.cnv.canvas.parentNode.offsetLeft,a=t.pageY-this.cnv.canvas.offsetTop-this.cnv.canvas.parentNode.offsetTop,n=e.files;if(n.length==0){var o="application/x-moz-file-promise-url";if(e.types.contains(o)){this._imageDropped(e.getData(o),s,a,false)}}else{var h=n[0],r=new FileReader;r.onload=i.proxy(function(t){this._imageDropped(t.target.result,s,a,true);r=null},this);r.readAsDataURL(h)}},this))}}},cropParams:null,crop:function(t){if(!!t)i.addClass(t,"bxu-edit-btn-active");var e=i.create("DIV",{attrs:{id:"crop"+this.id,className:"bx-bxu-canvas-crop-rectangle"},style:{border:"3px dashed gray",position:"absolute",display:"none",zIndex:1201}});this.cropParams={x:0,y:0,width:0,height:0,top:0,left:0,mousedown:i.delegate(function(t){i.fixEventPageXY(t);if(t.layerX||t.layerX==0){this.cropParams.left=t.layerX;this.cropParams.top=t.layerY}else if(t.offsetX||t.offsetX==0){this.cropParams.left=t.offsetX;this.cropParams.top=t.offsetY}else{this.cropParams.top=t.pageX-this.cnv.pos["left"];this.cropParams.left=t.pageY-this.cnv.pos["top"]}this.cropParams["~top"]=this.cropParams.top;this.cropParams["~left"]=this.cropParams.left;this.cropParams.x=t.pageX;this.cropParams.y=t.pageY;i.bind(document,"mousemove",this.cropParams.mousemove)},this),mousemove:i.delegate(function(t){i.fixEventPageXY(t);var s=t.pageX,a=t.pageY;this.cropParams.width=s-this.cropParams.x;if(this.cropParams.width<0){this.cropParams.left=this.cropParams["~left"]+this.cropParams.width;this.cropParams.width*=-1;if(this.cropParams.left<0){this.cropParams.left=0;this.cropParams.width=this.cropParams["~left"]}}else{this.cropParams.left=this.cropParams["~left"];if(this.cropParams.left+this.cropParams.width>this.cnv.pos.width)this.cropParams.width=this.cnv.pos.width-this.cropParams.left}this.cropParams.height=a-this.cropParams.y;if(this.cropParams.height<0){this.cropParams.top=this.cropParams["~top"]+this.cropParams.height;this.cropParams.height*=-1;if(this.cropParams.top<0){this.cropParams.top=0;this.cropParams.height=this.cropParams["~top"]}}else{this.cropParams.top=this.cropParams["~top"];if(this.cropParams.top+this.cropParams.height>this.cnv.pos.height)this.cropParams.height=this.cnv.pos.height-this.cropParams.top}i.adjust(e,{style:{left:this.cropParams.left+"px",top:this.cropParams.top+"px",width:this.cropParams.width-(e.borderLeft+e.borderRight)+"px",height:this.cropParams.height-(e.borderTop+e.borderBottom)+"px",display:"block"}})},this),mouseup:i.delegate(function(t){i.PreventDefault(t);if(this.cropParams.width>0&&this.cropParams.height>0){var e=i.create("CANVAS",{props:{width:this.cnv.width,height:this.cnv.height},style:{display:"none"}});e.getContext("2d").drawImage(this.cnv,0,0);this.setStyles(this.cropParams);this.ctx.save();this.ctx.drawImage(e,-this.getRealFromVis(this.cropParams["left"]),-this.getRealFromVis(this.cropParams["top"]));this.ctx.restore();e=null}this.cropParams.clear(t)},this),clear:i.delegate(function(s){if(!!t)i.removeClass(t,"bxu-edit-btn-active");i.unbind(this.cnv,"mousedown",this.cropParams.mousedown);i.unbind(document,"mousemove",this.cropParams.mousemove);i.unbind(this.cnv,"mouseup",this.cropParams.mouseup);i.unbind(e,"mouseup",this.cropParams.mouseup);i.unbind(document,"mouseup",this.cropParams.mouseup);this.cnv.parentNode.style.position=this.cnv.parentNode.style._position;this.cnv.parentNode.removeChild(e);e=null;this.cropParams=null},this)};i.bind(this.cnv,"mousedown",this.cropParams.mousedown);i.bind(this.cnv,"mouseup",this.cropParams.mouseup);i.bind(e,"mouseup",this.cropParams.mouseup);i.bind(document,"mouseup",this.cropParams.mouseup);this.cnv.pos=i.pos(this.cnv);this.cnv.parentNode.style._position=this.cnv.parentNode.style.position;this.cnv.parentNode.style.position="relative";this.cnv.parentNode.appendChild(e);for(var s=0,a=["top","right","bottom","left"];s<a.length;s++){e["b"+a[s]]=parseInt(i.style(e,"border-"+a[s]+"-width"));e["b"+a[s]]=!isNaN(e["b"+a[s]])&&e["b"+a[s]]>0?e["b"+a[s]]:0}e.borderLeft=e["bleft"];e.borderTop=e["btop"];e.borderRight=e["bright"];e.borderBottom=e["bbottom"]}}})(window);
//# sourceMappingURL=core_canvas.map.js