").css({height:this.getSettings("crop.height"),width:this.getSettings("crop.width"),display:"flex",alignItems:"center",justifyContent:"center"}),this.elements.$elementor.append(jQuery("
").css({fontSize:"85px"}).html(this.getSettings("empty_content_headline"))),document.body.prepend(this.elements.$elementor)}},{key:"loadExternalCss",value:function loadExternalCss(){var e=this,r=[this.getSettings("home_url")].concat((0,t.default)(this.getSettings("excluded_external_css_urls"))).map(function(e){return'[href^="'.concat(e,'"]')}).join(", ");jQuery("link").not(r).each(function(t,r){var o=jQuery(r),n=o.clone();n.attr("href",e.getScreenshotProxyUrl(o.attr("href"))),e.elements.$head.append(n),o.remove()})}},{key:"loadExternalImages",value:function loadExternalImages(){var e=this,t=this.getSettings("external_images_urls").map(function(e){return'img[src^="'.concat(e,'"]')}).join(", ");jQuery(t).each(function(t,r){var o=jQuery(r);o.attr("src",e.getScreenshotProxyUrl(o.attr("src")))})}},{key:"handleIFrames",value:function handleIFrames(){this.elements.$elementor.find("iframe").each(function(e,t){var r=jQuery(t),o=jQuery("
",{css:{background:"gray",width:r.width(),height:r.height()}});r.before(o),r.remove()})}},{key:"removeUnnecessaryElements",value:function removeUnnecessaryElements(){var e=this,t=0;this.getSettings("kit_id")||(this.elements.$sections.filter(function(r,o){var n=!1;return t>=e.getSettings("crop.height")&&(n=!0),t+=jQuery(o).outerHeight(),n}).each(function(e,t){t.remove()}),this.elements.$notElementorElements.remove())}},{key:"handleLinks",value:function handleLinks(){elementorCommon.elements.$body.find("a").attr("href","/")}},{key:"removeFirstSectionMargin",value:function removeFirstSectionMargin(){this.elements.$firstSection.css({marginTop:0})}},{key:"createImage",value:function createImage(){var e=this,t=new Promise(function(e){window.addEventListener("load",function(){e()})}),r=new Promise(function(t){setTimeout(function(){t()},e.getSettings("render_timeout"))});return Promise.race([t,r]).then(function(){return e.log("Start creating screenshot."),e.getSettings("isDebugSvg")?(domtoimage.toSvg(document.body,{imagePlaceholder:e.getSettings("image_placeholder")}).then(function(t){return e.download(t)}),Promise.reject("Debug SVG.")):/^((?!chrome|android).)*safari/i.test(window.userAgent)?(e.log('Creating screenshot with "html2canvas"'),html2canvas(document.body).then(function(e){return e.toDataURL("image/png")})):(e.log('Creating screenshot with "dom-to-image"'),domtoimage.toPng(document.body,{imagePlaceholder:e.getSettings("image_placeholder")}).catch(function(){return html2canvas(document.body).then(function(e){return e.toDataURL("image/png")})}))})}},{key:"download",value:function download(e){var t=jQuery("",{href:e,download:"debugSvg.svg",html:"Download SVG"});elementorCommon.elements.$body.append(t),t.trigger("click")}},{key:"createImageElement",value:function createImageElement(e){var t=new Image;return t.src=e,new Promise(function(e){t.onload=function(){return e(t)}})}},{key:"cropCanvas",value:function cropCanvas(e){var t=this.getSettings("crop.width"),r=this.getSettings("crop.height"),cropCanvas=document.createElement("canvas"),o=cropCanvas.getContext("2d"),n=t/e.width;return cropCanvas.width=t,cropCanvas.height=r>e.height?e.height:r,o.drawImage(e,0,0,e.width,e.height,0,0,e.width*n,e.height*n),Promise.resolve(cropCanvas)}},{key:"save",value:function save(e){var t=this,o=this.getSaveAction(),n=o.key,s=o.action,i=(0,r.default)((0,r.default)({},n,this.getSettings(n)),"screenshot",e.toDataURL("image/png"));return new Promise(function(e,r){if("kit_id"===n)return e(i.screenshot);elementorCommon.ajax.addRequest(s,{data:i,success:function success(r){t.log("Screenshot created: ".concat(encodeURI(r))),e(r)},error:function error(){t.log("Failed to create screenshot."),r()}})})}},{key:"markAsFailed",value:function markAsFailed(e){var t=this;return new Promise(function(r,o){var n=t.getSettings("template_id"),s=t.getSettings("post_id");if(t.getSettings("kit_id"))r();else{var i=n?"template_screenshot_failed":"screenshot_failed",a=n?{template_id:n,error:e.message||e.toString()}:{post_id:s};elementorCommon.ajax.addRequest(i,{data:a,success:function success(){t.log("Marked as failed."),r()},error:function error(){t.log("Failed to mark this screenshot as failed."),o()}})}})}},{key:"getScreenshotProxyUrl",value:function getScreenshotProxyUrl(e){return"".concat(this.getSettings("home_url"),"?screenshot_proxy&nonce=").concat(this.getSettings("nonce"),"&href=").concat(e)}},{key:"screenshotSucceed",value:function screenshotSucceed(e){this.screenshotDone(!0,e)}},{key:"screenshotFailed",value:function screenshotFailed(e){var t=this;this.log(e,null),this.markAsFailed(e).then(function(){return t.screenshotDone(!1)})}},{key:"screenshotDone",value:function screenshotDone(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;clearTimeout(this.timeoutTimer),this.timeoutTimer=null;var r=this.getSaveAction(),o=r.message,n=r.key;window.parent.postMessage({name:o,success:e,id:this.getSettings(n),imageUrl:t},"*"),this.log("Screenshot ".concat(e?"Succeed":"Failed","."),"timeEnd")}},{key:"log",value:function log(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"timeLog";this.getSettings("isDebug")&&(console.log("string"==typeof e?"".concat(this.getSettings("post_id")," - ").concat(e):e),t&&console[t](this.getSettings("timer_label")))}},{key:"getSaveAction",value:function getSaveAction(){var e=this.getSettings();return e.kit_id?{message:"kit-screenshot-done",action:"update_kit_preview",key:"kit_id"}:e.template_id?{message:"library/capture-screenshot-done",action:"save_template_screenshot",key:"template_id"}:{message:"capture-screenshot-done",action:"screenshot_save",key:"post_id"}}}])}(elementorModules.ViewModule);jQuery(function(){new u})})()})();