function _extends(){return(_extends=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var a,n=arguments[e];for(a in n)Object.prototype.hasOwnProperty.call(n,a)&&(t[a]=n[a])}return t}).apply(this,arguments)}var NRF_Signature_Item=function(){function t(t){this.wrapper=t,this.canvas=this.wrapper.querySelector("canvas"),this.signaturePad=new SignaturePad(this.canvas,{backgroundColor:"transparent",penColor:this.canvas.dataset.penColor}),this.input=this.wrapper.querySelector('input[type="hidden"]'),this.clearButton=this.wrapper.querySelector(".nrf-signature-clear"),this.resetButton=this.wrapper.querySelector(".nrf-signature-reset"),this.lockedCanvasWidth=0,this.lockedCanvasHeight=0,this.wrapper.signature=this}var e=t.prototype;return e.init=function(){this.lockCanvasDimensions(),this.onCanvasUpdateRatio(),this.setValue(),this.initEvents()},e.initEvents=function(){var a=this,n=this.canvas,i=this.wrapper,r=(this.signaturePad.addEventListener("afterUpdateStroke",function(){i.classList.add("painted")}),this.signaturePad.addEventListener("endStroke",function(t){var e=a.removeBlanks(n);e&&(e=a.updateCanvasColor(e,"#000"),n.nextElementSibling.value=e.toDataURL(),i.classList.add("painted"))}),this.resetButton.addEventListener("click",function(t){this.resetSignature(t)}.bind(this)),this.clearButton.addEventListener("click",function(t){this.clearSignature(t)}.bind(this)),this.canvas.offsetWidth),o=this.canvas.offsetHeight,t=this.debounce(function(){var t,e,a,n,i=this.canvas.offsetWidth,s=this.canvas.offsetHeight;i===r&&s===o||(t=this.signaturePad.isEmpty()?null:this.signaturePad.toData(),e=this.input.value,this.onCanvasUpdateRatio()&&(t&&t.length?(a=r?i/r:1,n=o?s/o:1,this.signaturePad.fromData(this.scaleSignatureData(t,a,n)),this.wrapper.classList.add("painted")):e?(this.signaturePad.fromDataURL(e),this.wrapper.classList.add("painted")):this.wrapper.classList.remove("painted"),r=i,o=s))}.bind(this));window.addEventListener("resize",t),window.addEventListener("orientationchange",t)},e.scaleSignatureData=function(t,e,a){return Array.isArray(t)&&(e||a)?t.map(function(t){return t&&Array.isArray(t.points)?_extends({},t,{points:t.points.map(function(t){return _extends({},t,{x:t.x*e,y:t.y*a})})}):t}):t},e.lockCanvasDimensions=function(){var t,e;this.lockedCanvasWidth||this.lockedCanvasHeight||(t=this.canvas.offsetWidth,e=this.canvas.offsetHeight,t&&e&&(this.lockedCanvasWidth=t,this.lockedCanvasHeight=e,this.canvas.style.maxWidth=t+"px",this.canvas.style.width="100%",this.canvas.style.height=e+"px"))},e.updateCanvasColor=function(t,e){var a=t.getContext("2d");return a.save(),a.globalCompositeOperation="source-atop",a.fillStyle=e,a.fillRect(0,0,t.width,t.height),a.restore(),t},e.removeBlanks=function(t){for(var e=t.getContext("2d"),a=t.width,n=t.height,i=e.getImageData(0,0,a,n),s=a+1,r=-1,o=n+1,c=-1,h=0,u=0,u=0;u<n;u++)for(h=0;h<a;h++)0<i.data[3+4*(u*a+h)]&&(h<s&&(s=h),r<h&&(r=h),u<o&&(o=u),c<u)&&(c=u);var d,l,t=r-s,v=c-o;return t<=0||v<=0?null:(e=e.getImageData(s,o,t,v),l=(d=document.createElement("canvas")).getContext("2d"),d.width=t,d.height=v,l.putImageData(e,0,0),d)},e.clearSignature=function(t){t.target.closest(".nrf-signature-clear")&&this.clear()},e.resetSignature=function(t){t.target.closest(".nrf-signature-reset")&&(this.clear(),this.reset())},e.debounce=function(e){var a;return function(t){a&&clearTimeout(a),a=setTimeout(e,100,t)}},e.onCanvasUpdateRatio=function(){this.lockCanvasDimensions();var t,e=this.canvas.offsetWidth,a=this.canvas.offsetHeight;return!(!e||!a||(t=Math.max(window.devicePixelRatio||1,1),this.canvas.width=e*t,this.canvas.height=a*t,this.canvas.getContext("2d").setTransform(t,0,0,t,0,0),this.signaturePad.clear(),0))},e.setValue=function(t){""!=(t=""!=(t=void 0===t?"":t)?t:this.input.value)&&(this.signaturePad.fromDataURL(t),this.wrapper.classList.add("painted"))},e.clear=function(){this.wrapper.classList.remove("painted"),this.signaturePad.clear(),this.input.value=""},e.reset=function(){var t=this.wrapper.querySelector(".initial-value").value;this.setValue(t)},t}(),NRF_Signature_Loader=function(){function t(){this.init()}return t.prototype.init=function(){var e;window.IntersectionObserver&&(e=new IntersectionObserver(function(t,e){t.forEach(function(t){t.isIntersecting&&(new NRF_Signature_Item(t.target).init(),e.unobserve(t.target))})},{rootMargin:"0px 0px 0px 0px"}),document.querySelectorAll(".nrf-widget.signature").forEach(function(t){e.observe(t)}))},t}();"loading"!=document.readyState?new NRF_Signature_Loader:document.addEventListener("DOMContentLoaded",function(){new NRF_Signature_Loader});

