function createPreviewTemplate(e,a,r,t,o,n,l){var s=new fabric.Canvas(jQuery("canvas",jQuery("#preview-canvas-container")).attr("id"));fabric.Object.NUM_FRACTION_DIGITS=5;var f,c,_,h,u,p,v,g,m,d,y,w,F,b,j,Q,x=parseFloat(minerva_configurator_vars.low_image_width),C=parseFloat(minerva_configurator_vars.low_image_height),M=parseFloat(minerva_configurator_vars.hi_image_width),z=parseFloat(minerva_configurator_vars.hi_image_height),k=minerva_configurator_vars.assets,I=minerva_configurator_vars.assets_hires,D=jQuery(".pen-preview.imprint .view"),R=D.length,A=z/C,L=minerva_configurator_vars.wp_content_url+"/",S=parseFloat(minerva_configurator_vars.space),T=[];switch(e){case"low":f=1,_="all"==n?x*R+S*(R-1):x,h=C,c=x+S,L+=k,templateName=minerva_configurator_vars.low_template_filename,u=parseFloat(minerva_configurator_vars.low_template_image_width),p=parseFloat(minerva_configurator_vars.low_template_image_height),m=parseFloat(minerva_configurator_vars.low_xt),d=parseFloat(minerva_configurator_vars.low_yt),T=[parseFloat(minerva_configurator_vars.low_body_font_size),parseFloat(minerva_configurator_vars.low_heading_font_size)],y=parseFloat(minerva_configurator_vars.low_logo_width),w=parseFloat(minerva_configurator_vars.low_logo_height),parseFloat(minerva_configurator_vars.low_crop_margin_left),F=parseFloat(minerva_configurator_vars.low_crop_margin_right),b=parseFloat(minerva_configurator_vars.low_crop_margin_top),parseFloat(minerva_configurator_vars.low_crop_margin_bottom);break;case"hi":f=A,_="all"==n?M*R+S*A*(R-1):M,h=z,c=M+S*A,L+=I,templateName=minerva_configurator_vars.hi_template_filename,u=parseFloat(minerva_configurator_vars.hi_template_image_width),p=parseFloat(minerva_configurator_vars.hi_template_image_height),m=parseFloat(minerva_configurator_vars.hi_xt),d=parseFloat(minerva_configurator_vars.hi_yt),T=[parseFloat(minerva_configurator_vars.hi_body_font_size),parseFloat(minerva_configurator_vars.hi_heading_font_size)],y=parseFloat(minerva_configurator_vars.hi_logo_width),w=parseFloat(minerva_configurator_vars.hi_logo_height),parseFloat(minerva_configurator_vars.hi_crop_margin_left),F=parseFloat(minerva_configurator_vars.hi_crop_margin_right),b=parseFloat(minerva_configurator_vars.hi_crop_margin_top),parseFloat(minerva_configurator_vars.hi_crop_margin_bottom)}is_defined(Cookies.get("dealer"))&&(templateName+="-dealer"),L+="/"+templateName+"."+t,a?(v=u,g=p,j=u/2-_/2,Q="low"==e?375-h/2:p/2-h/2-.045*h):(v=_,g=h,j=0,Q=0),s.setBackgroundColor(""),s.setDimensions({width:v,height:g});var U={};"all"==n?D.each(function(e,a){U[jQuery(a).data("view-code")]=j+c*e}):U[n]=j;var N,O=[];jQuery.when(function(e){var a=jQuery.Deferred();return fabric.Image.fromURL(e,function(e){e.set({left:0,top:0}),N=e,a.resolve()}),a.promise()}(L)).done(function(){a&&s.add(N),D.each(function(a,r){var t=jQuery(this),i=t.data("view-code");if("all"==n||i==n){O.push(function(a,r){var t=jQuery.Deferred(),i=[],n=[];return jQuery(".refill-picture:not(.hidden), .pen-picture",a).each(function(a,t){var o="low"==e?jQuery(this).attr("src"):jQuery(this).attr("src").replace(k,I);n.push(function(e,a){var t=jQuery.Deferred();return fabric.Image.fromURL(e,function(e){e.set({left:U[r],top:Q+0}),i[a]=e,t.resolve()}),t.promise()}(o,a))}),jQuery.when.apply($,n).done(function(){if(jQuery(i).each(function(e,a){s.add(a)}),o){var e=[],n=[];jQuery(".print-area",a).each(function(a,t){var i=jQuery(this),o=i.data("image-shift")?parseFloat(i.data("image-shift")):0,l=parseFloat(i.css("width").replace("px",""))*A,c=parseFloat(i.css("height").replace("px",""))*A,_=parseFloat(i.css("left").replace("px",""))*f+U[r],h=parseFloat(i.css("top").replace("px",""))*f+Q;if(jQuery(".print-area-content img",i).length>0){var u=jQuery(".print-area-content img",i),p=u.attr("src"),v=u[0];n.push(function(a){var r=jQuery.Deferred();return fabric.Image.fromURL(a,function(a){a.set({clipPath:new fabric.Rect({left:-l/2-o*A,top:-c/2,width:l,height:c,fill:"#000000"}),left:_-Math.abs(v.naturalWidth/A*f/2+(-l/A*f/2-o*f)),top:h,scaleX:f/A,scaleY:f/A}),e.push(a),r.resolve()}),r.promise()}(p))}if(jQuery(".print-area-content span",i).length>0){l*=f/A,c*=f/A;var g=jQuery(".print-area-content span",i)[0];if(jQuery(g).hasClass("input"))var m=jQuery(g).text();else m=jQuery(g).html().replace(/
/g,"\n");var d,y,w,F=jQuery(g).parent().data("text-rotation"),b=_+l/2,j=h+c/2,x=new fabric.Text(m,{fontFamily:jQuery(g).css("font-family"),fontSize:parseFloat(jQuery(g).css("font-size").replace("px",""))*f,fontWeight:jQuery(g).css("font-weight"),fontStyle:jQuery(g).css("font-style"),fill:rgb2hex(jQuery(g).css("color")),angle:F,originX:"center",originY:"center",textAlign:jQuery(g).css("text-align")}),C=x.width,M=x.height,z=270==F?"fbtt":"fttb";switch(jQuery(g).css("text-align")+"-"+z){case"left-fbtt":d=c/2-C/2,w=-C/2;break;case"center-fbtt":d=0,w=-c/2;break;case"right-fbtt":d=-c/2+C/2,w=-(c-C/2);break;case"left-fttb":d=-c/2+C/2,w=-C/2;break;case"center-fttb":d=0,w=-c/2;break;case"right-fttb":d=c/2-C/2,w=-(c-C/2)}x.set({left:b+o*f,top:j+d});var k,I=!0,D=Math.floor(100*c)/100;switch(z){case"fbtt":0==o?y=-Math.floor(l/2*100)/100:o<0?(y=(y=_-(b+o*f))<0?-Math.floor(100*Math.abs(y))/100:y,b+o*f+x.height/2<_&&(I=!1)):o>0&&(y=-M/2,b+o*f-x.height/2>_+l&&(I=!1)),k=Math.floor(100*l)/100;break;case"fttb":0==o?(y=-Math.floor(l/2*100)/100,k=Math.floor(100*l)/100):o<0?(y=(y=-(_-(b+o*f)))>0?Math.floor(100*Math.abs(y))/100:y,k=-Math.floor(100*l)/100,b+o*f+x.height/2<_&&(I=!1)):o>0&&(y=M/2,k=Math.floor(100*l)/100,b+o*f-x.height/2>_+l&&(I=!1))}x.clipPath=new fabric.Rect({left:w,top:y,width:D,height:k,fill:"#000000"}),I&&s.add(x)}}),jQuery.when.apply($,n).done(function(){jQuery(e).each(function(e,a){s.add(a)}),t.resolve()})}else t.resolve()}),t.promise()}(t,i))}}),jQuery.when.apply($,O).done(function(){a?new FontFaceObserver("avenir55heavy").load().then(function(){var e=getConfigurationSummary(),a={},o=0;for(i=0;io?y/i:w/o,a=Math.min(y/i,w/o),e.scale(parseFloat(a)),e.set({left:u-F-i*a,top:b}),s.add(e),s.renderAll(),renderComplete(null,s,t,1,r,l)},{crossOrigin:"Anonymous"})}else renderComplete(null,s,t,1,r,l)}).catch(function(e){console.log(e)}):renderComplete(null,s,t,1,r,l)})})}function resizeCanvas(e,a,r,t,i){if(1!=e){var o=new Image;o.src=a,o.onload=function(){var n=new fabric.Canvas(jQuery("")[0]);n.setDimensions({width:o.width*e,height:o.height*e});var l=new fabric.Image(o,{left:0,top:0});l.scale(e),n.add(l),n.renderAll(),a=n.toDataURL({format:r,quality:1,multiplier:1/t}),"function"==typeof i&&null!=i&&i(a)}}else"function"==typeof i&&null!=i&&i(a)}function renderComplete(e,a,r,t,i,o){resizeCanvas(i,a.toDataURL({format:r,quality:1,multiplier:1/t}),r,t,o)}