/home/tuzdhajd/ablacktime.com/wp-content/plugins/ninja-forms/build/fields.js
(()=>{var t={2694(t,e,n){"use strict";var i=n(6925);function r(){}function o(){}o.resetWarningCache=r,t.exports=function(){function t(t,e,n,r,o,a){if(a!==i){var s=new Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types");throw s.name="Invariant Violation",s}}function e(){return t}t.isRequired=t;var n={array:t,bigint:t,bool:t,func:t,number:t,object:t,string:t,symbol:t,any:t,arrayOf:e,element:t,elementType:t,instanceOf:e,node:t,objectOf:e,oneOf:e,oneOfType:e,shape:e,exact:e,checkPropTypes:o,resetWarningCache:r};return n.PropTypes=n,n}},5556(t,e,n){t.exports=n(2694)()},6567(t){t.exports=function(t){function e(i){if(n[i])return n[i].exports;var r=n[i]={exports:{},id:i,loaded:!1};return t[i].call(r.exports,r,r.exports,e),r.loaded=!0,r.exports}var n={};return e.m=t,e.c=n,e.p="",e(0)}([function(t,e){"use strict";function n(t,e,n,i){return function(t,e,n,i){return{red:i[4*(n*e+t)],green:i[4*(n*e+t)+1],blue:i[4*(n*e+t)+2],alpha:i[4*(n*e+t)+3]}}(t,e,n,i).alpha}function i(t,e,i,r){for(var o=t?1:-1,a=t?0:i-1;t?a<i:a>-1;a+=o)for(var s=0;s<e;s++)if(n(s,a,e,r))return a;return null}function r(t,e,i,r){for(var o=t?1:-1,a=t?0:e-1;t?a<e:a>-1;a+=o)for(var s=0;s<i;s++)if(n(a,s,e,r))return a;return null}Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t){var e=t.getContext("2d"),n=t.width,o=t.height,a=e.getImageData(0,0,n,o).data,s=i(!0,n,o,a),l=i(!1,n,o,a),c=r(!0,n,o,a),u=r(!1,n,o,a)-c+1,d=l-s+1,h=e.getImageData(c,s,u,d);return t.width=u,t.height=d,e.clearRect(0,0,u,d),e.putImageData(h,0,0),t}}])},6925(t){"use strict";t.exports="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"}},e={};function n(i){var r=e[i];if(void 0!==r)return r.exports;var o=e[i]={exports:{}};return t[i].call(o.exports,o,o.exports,n),o.exports}(()=>{"use strict";const t=window.wp.element,e=window.wp.components,i=window.wp.i18n;function r(){return r=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var i in n)({}).hasOwnProperty.call(n,i)&&(t[i]=n[i])}return t},r.apply(null,arguments)}function o(t){return o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},o(t)}function a(t,e){return a=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},a(t,e)}function s(t){return s=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},s(t)}function l(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(l=function(){return!!t})()}var c=n(5556);const u=window.React;function d(t,e,n){this.x=t,this.y=e,this.time=n||(new Date).getTime()}function h(t,e,n,i){this.startPoint=t,this.control1=e,this.control2=n,this.endPoint=i}function f(t,e){var n=this,i=e||{};this.velocityFilterWeight=i.velocityFilterWeight||.7,this.minWidth=i.minWidth||.5,this.maxWidth=i.maxWidth||2.5,this.throttle="throttle"in i?i.throttle:16,this.minDistance="minDistance"in i?i.minDistance:5,this.throttle?this._strokeMoveUpdate=function(t,e,n){var i,r,o,a=null,s=0;n||(n={});var l=function(){s=!1===n.leading?0:Date.now(),a=null,o=t.apply(i,r),a||(i=r=null)};return function(){var c=Date.now();s||!1!==n.leading||(s=c);var u=e-(c-s);return i=this,r=arguments,u<=0||u>e?(a&&(clearTimeout(a),a=null),s=c,o=t.apply(i,r),a||(i=r=null)):a||!1===n.trailing||(a=setTimeout(l,u)),o}}(f.prototype._strokeUpdate,this.throttle):this._strokeMoveUpdate=f.prototype._strokeUpdate,this.dotSize=i.dotSize||function(){return(this.minWidth+this.maxWidth)/2},this.penColor=i.penColor||"black",this.backgroundColor=i.backgroundColor||"rgba(0,0,0,0)",this.onBegin=i.onBegin,this.onEnd=i.onEnd,this._canvas=t,this._ctx=t.getContext("2d"),this.clear(),this._handleMouseDown=function(t){1===t.which&&(n._mouseButtonDown=!0,n._strokeBegin(t))},this._handleMouseMove=function(t){n._mouseButtonDown&&n._strokeMoveUpdate(t)},this._handleMouseUp=function(t){1===t.which&&n._mouseButtonDown&&(n._mouseButtonDown=!1,n._strokeEnd(t))},this._handleTouchStart=function(t){if(1===t.targetTouches.length){var e=t.changedTouches[0];n._strokeBegin(e)}},this._handleTouchMove=function(t){t.preventDefault();var e=t.targetTouches[0];n._strokeMoveUpdate(e)},this._handleTouchEnd=function(t){t.target===n._canvas&&(t.preventDefault(),n._strokeEnd(t))},this.on()}d.prototype.velocityFrom=function(t){return this.time!==t.time?this.distanceTo(t)/(this.time-t.time):1},d.prototype.distanceTo=function(t){return Math.sqrt(Math.pow(this.x-t.x,2)+Math.pow(this.y-t.y,2))},d.prototype.equals=function(t){return this.x===t.x&&this.y===t.y&&this.time===t.time},h.prototype.length=function(){for(var t=0,e=void 0,n=void 0,i=0;i<=10;i+=1){var r=i/10,o=this._point(r,this.startPoint.x,this.control1.x,this.control2.x,this.endPoint.x),a=this._point(r,this.startPoint.y,this.control1.y,this.control2.y,this.endPoint.y);if(i>0){var s=o-e,l=a-n;t+=Math.sqrt(s*s+l*l)}e=o,n=a}return t},h.prototype._point=function(t,e,n,i,r){return e*(1-t)*(1-t)*(1-t)+3*n*(1-t)*(1-t)*t+3*i*(1-t)*t*t+r*t*t*t},f.prototype.clear=function(){var t=this._ctx,e=this._canvas;t.fillStyle=this.backgroundColor,t.clearRect(0,0,e.width,e.height),t.fillRect(0,0,e.width,e.height),this._data=[],this._reset(),this._isEmpty=!0},f.prototype.fromDataURL=function(t){var e=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=new Image,r=n.ratio||window.devicePixelRatio||1,o=n.width||this._canvas.width/r,a=n.height||this._canvas.height/r;this._reset(),i.src=t,i.onload=function(){e._ctx.drawImage(i,0,0,o,a)},this._isEmpty=!1},f.prototype.toDataURL=function(t){var e;if("image/svg+xml"===t)return this._toSVG();for(var n=arguments.length,i=Array(n>1?n-1:0),r=1;r<n;r++)i[r-1]=arguments[r];return(e=this._canvas).toDataURL.apply(e,[t].concat(i))},f.prototype.on=function(){this._handleMouseEvents(),this._handleTouchEvents()},f.prototype.off=function(){this._canvas.removeEventListener("mousedown",this._handleMouseDown),this._canvas.removeEventListener("mousemove",this._handleMouseMove),document.removeEventListener("mouseup",this._handleMouseUp),this._canvas.removeEventListener("touchstart",this._handleTouchStart),this._canvas.removeEventListener("touchmove",this._handleTouchMove),this._canvas.removeEventListener("touchend",this._handleTouchEnd)},f.prototype.isEmpty=function(){return this._isEmpty},f.prototype._strokeBegin=function(t){this._data.push([]),this._reset(),this._strokeUpdate(t),"function"==typeof this.onBegin&&this.onBegin(t)},f.prototype._strokeUpdate=function(t){var e=t.clientX,n=t.clientY,i=this._createPoint(e,n),r=this._data[this._data.length-1],o=r&&r[r.length-1],a=o&&i.distanceTo(o)<this.minDistance;if(!o||!a){var s=this._addPoint(i),l=s.curve,c=s.widths;l&&c&&this._drawCurve(l,c.start,c.end),this._data[this._data.length-1].push({x:i.x,y:i.y,time:i.time,color:this.penColor})}},f.prototype._strokeEnd=function(t){var e=this.points.length>2,n=this.points[0];if(!e&&n&&this._drawDot(n),n){var i=this._data[this._data.length-1],r=i[i.length-1];n.equals(r)||i.push({x:n.x,y:n.y,time:n.time,color:this.penColor})}"function"==typeof this.onEnd&&this.onEnd(t)},f.prototype._handleMouseEvents=function(){this._mouseButtonDown=!1,this._canvas.addEventListener("mousedown",this._handleMouseDown),this._canvas.addEventListener("mousemove",this._handleMouseMove),document.addEventListener("mouseup",this._handleMouseUp)},f.prototype._handleTouchEvents=function(){this._canvas.style.msTouchAction="none",this._canvas.style.touchAction="none",this._canvas.addEventListener("touchstart",this._handleTouchStart),this._canvas.addEventListener("touchmove",this._handleTouchMove),this._canvas.addEventListener("touchend",this._handleTouchEnd)},f.prototype._reset=function(){this.points=[],this._lastVelocity=0,this._lastWidth=(this.minWidth+this.maxWidth)/2,this._ctx.fillStyle=this.penColor},f.prototype._createPoint=function(t,e,n){var i=this._canvas.getBoundingClientRect();return new d(t-i.left,e-i.top,n||(new Date).getTime())},f.prototype._addPoint=function(t){var e=this.points;if(e.push(t),e.length>2){3===e.length&&e.unshift(e[0]);var n=this._calculateCurveControlPoints(e[0],e[1],e[2]).c2,i=this._calculateCurveControlPoints(e[1],e[2],e[3]).c1,r=new h(e[1],n,i,e[2]),o=this._calculateCurveWidths(r);return e.shift(),{curve:r,widths:o}}return{}},f.prototype._calculateCurveControlPoints=function(t,e,n){var i=t.x-e.x,r=t.y-e.y,o=e.x-n.x,a=e.y-n.y,s=(t.x+e.x)/2,l=(t.y+e.y)/2,c=(e.x+n.x)/2,u=(e.y+n.y)/2,h=Math.sqrt(i*i+r*r),f=Math.sqrt(o*o+a*a),p=f/(h+f),g=c+(s-c)*p,m=u+(l-u)*p,v=e.x-g,_=e.y-m;return{c1:new d(s+v,l+_),c2:new d(c+v,u+_)}},f.prototype._calculateCurveWidths=function(t){var e=t.startPoint,n=t.endPoint,i={start:null,end:null},r=this.velocityFilterWeight*n.velocityFrom(e)+(1-this.velocityFilterWeight)*this._lastVelocity,o=this._strokeWidth(r);return i.start=this._lastWidth,i.end=o,this._lastVelocity=r,this._lastWidth=o,i},f.prototype._strokeWidth=function(t){return Math.max(this.maxWidth/(t+1),this.minWidth)},f.prototype._drawPoint=function(t,e,n){var i=this._ctx;i.moveTo(t,e),i.arc(t,e,n,0,2*Math.PI,!1),this._isEmpty=!1},f.prototype._drawCurve=function(t,e,n){var i=this._ctx,r=n-e,o=Math.floor(t.length());i.beginPath();for(var a=0;a<o;a+=1){var s=a/o,l=s*s,c=l*s,u=1-s,d=u*u,h=d*u,f=h*t.startPoint.x;f+=3*d*s*t.control1.x,f+=3*u*l*t.control2.x,f+=c*t.endPoint.x;var p=h*t.startPoint.y;p+=3*d*s*t.control1.y,p+=3*u*l*t.control2.y,p+=c*t.endPoint.y;var g=e+c*r;this._drawPoint(f,p,g)}i.closePath(),i.fill()},f.prototype._drawDot=function(t){var e=this._ctx,n="function"==typeof this.dotSize?this.dotSize():this.dotSize;e.beginPath(),this._drawPoint(t.x,t.y,n),e.closePath(),e.fill()},f.prototype._fromData=function(t,e,n){for(var i=0;i<t.length;i+=1){var r=t[i];if(r.length>1)for(var o=0;o<r.length;o+=1){var a=r[o],s=new d(a.x,a.y,a.time),l=a.color;if(0===o)this.penColor=l,this._reset(),this._addPoint(s);else if(o!==r.length-1){var c=this._addPoint(s),u=c.curve,h=c.widths;u&&h&&e(u,h,l)}}else this._reset(),n(r[0])}},f.prototype._toSVG=function(){var t=this,e=this._data,n=this._canvas,i=Math.max(window.devicePixelRatio||1,1),r=n.width/i,o=n.height/i,a=document.createElementNS("http://www.w3.org/2000/svg","svg");a.setAttributeNS(null,"width",n.width),a.setAttributeNS(null,"height",n.height),this._fromData(e,function(t,e,n){var i=document.createElement("path");if(!(isNaN(t.control1.x)||isNaN(t.control1.y)||isNaN(t.control2.x)||isNaN(t.control2.y))){var r="M "+t.startPoint.x.toFixed(3)+","+t.startPoint.y.toFixed(3)+" C "+t.control1.x.toFixed(3)+","+t.control1.y.toFixed(3)+" "+t.control2.x.toFixed(3)+","+t.control2.y.toFixed(3)+" "+t.endPoint.x.toFixed(3)+","+t.endPoint.y.toFixed(3);i.setAttribute("d",r),i.setAttribute("stroke-width",(2.25*e.end).toFixed(3)),i.setAttribute("stroke",n),i.setAttribute("fill","none"),i.setAttribute("stroke-linecap","round"),a.appendChild(i)}},function(e){var n=document.createElement("circle"),i="function"==typeof t.dotSize?t.dotSize():t.dotSize;n.setAttribute("r",i),n.setAttribute("cx",e.x),n.setAttribute("cy",e.y),n.setAttribute("fill",e.color),a.appendChild(n)});var s='<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 '+r+" "+o+'" width="'+r+'" height="'+o+'">',l=a.innerHTML;if(void 0===l){var c=document.createElement("dummy"),u=a.childNodes;c.innerHTML="";for(var d=0;d<u.length;d+=1)c.appendChild(u[d].cloneNode(!0));l=c.innerHTML}return"data:image/svg+xml;base64,"+btoa(s+l+"</svg>")},f.prototype.fromData=function(t){var e=this;this.clear(),this._fromData(t,function(t,n){return e._drawCurve(t,n.start,n.end)},function(t){return e._drawDot(t)}),this._data=t},f.prototype.toData=function(){return this._data};const p=f;var g=n(6567),m=["canvasProps","clearOnResize"],v=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&a(t,e)}(d,t);var e,n,i,c=(e=d,n=l(),function(){var t,i=s(e);if(n){var r=s(this).constructor;t=Reflect.construct(i,arguments,r)}else t=i.apply(this,arguments);return function(t,e){if(e&&("object"==o(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(this,t)});function d(){var t;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,d);for(var e=arguments.length,n=new Array(e),i=0;i<e;i++)n[i]=arguments[i];return(t=c.call.apply(c,[this].concat(n))).staticThis=t.constructor,t._sigPad=null,t._canvas=null,t.setRef=function(e){t._canvas=e,null===t._canvas&&(t._sigPad=null)},t._excludeOurProps=function(){var e=t.props;e.canvasProps,e.clearOnResize;var n=function(t,e){if(null==t)return{};var n,i,r=function(t,e){if(null==t)return{};var n={};for(var i in t)if({}.hasOwnProperty.call(t,i)){if(-1!==e.indexOf(i))continue;n[i]=t[i]}return n}(t,e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);for(i=0;i<o.length;i++)n=o[i],-1===e.indexOf(n)&&{}.propertyIsEnumerable.call(t,n)&&(r[n]=t[n])}return r}(e,m);return n},t.componentDidMount=function(){var e=t.getCanvas();t._sigPad=new p(e,t._excludeOurProps()),t._resizeCanvas(),t.on()},t.componentWillUnmount=function(){t.off()},t.componentDidUpdate=function(){Object.assign(t._sigPad,t._excludeOurProps())},t.getCanvas=function(){if(null===t._canvas)throw t.staticThis.refNullError;return t._canvas},t.getTrimmedCanvas=function(){var e=t.getCanvas(),n=document.createElement("canvas");return n.width=e.width,n.height=e.height,n.getContext("2d").drawImage(e,0,0),g(n)},t.getSignaturePad=function(){if(null===t._sigPad)throw t.staticThis.refNullError;return t._sigPad},t._checkClearOnResize=function(){t.props.clearOnResize&&t._resizeCanvas()},t._resizeCanvas=function(){var e,n,i=null!==(e=t.props.canvasProps)&&void 0!==e?e:{},r=i.width,o=i.height;if(void 0===r||void 0===o){var a=t.getCanvas(),s=Math.max(null!==(n=window.devicePixelRatio)&&void 0!==n?n:1,1);void 0===r&&(a.width=a.offsetWidth*s),void 0===o&&(a.height=a.offsetHeight*s),a.getContext("2d").scale(s,s),t.clear()}},t.render=function(){var e=t.props.canvasProps;return u.createElement("canvas",r({ref:t.setRef},e))},t.on=function(){return window.addEventListener("resize",t._checkClearOnResize),t.getSignaturePad().on()},t.off=function(){return window.removeEventListener("resize",t._checkClearOnResize),t.getSignaturePad().off()},t.clear=function(){return t.getSignaturePad().clear()},t.isEmpty=function(){return t.getSignaturePad().isEmpty()},t.fromDataURL=function(e,n){return t.getSignaturePad().fromDataURL(e,n)},t.toDataURL=function(e,n){return t.getSignaturePad().toDataURL(e,n)},t.fromData=function(e){return t.getSignaturePad().fromData(e)},t.toData=function(){return t.getSignaturePad().toData()},t}return i=d,Object.defineProperty(i,"prototype",{writable:!1}),i}(u.Component);v.propTypes={velocityFilterWeight:c.number,minWidth:c.number,maxWidth:c.number,minDistance:c.number,dotSize:c.oneOfType([c.number,c.func]),penColor:c.string,throttle:c.number,onEnd:c.func,onBegin:c.func,canvasProps:c.object,clearOnResize:c.bool},v.defaultProps={clearOnResize:!0},v.refNullError=new Error("react-signature-canvas is currently mounting or unmounting: React refs are null during this phase.");const _=window.ReactJSXRuntime,y=({onChange:n,value:r,fieldSettings:o,width:a=400,height:s=150,penColor:l="#000000",backgroundColor:c="transparent"})=>{const u=(0,t.useRef)(null),d=(0,t.useRef)(null),[h,f]=(0,t.useState)(!0),[p,g]=(0,t.useState)(!0),[m,y]=(0,t.useState)(!1),[w,x]=(0,t.useState)(a),b=(0,t.useRef)(null);(0,t.useEffect)(()=>{if(!m&&u.current){if(!r||!r.signature_data)return void(u.current.isEmpty()||(u.current.clear(),f(!0),g(!0),b.current=null));if(r.signature_data){if(b.current===r.signature_data)return;try{u.current.fromDataURL(r.signature_data),f(!1),g(!1),b.current=r.signature_data}catch(t){console.error("Error loading signature:",t)}}}},[r,m]),(0,t.useEffect)(()=>{const t=()=>{if(d.current){const t=d.current.offsetWidth,e=Math.min(t,a);x(e)}};let e;t();const n=()=>{e&&clearTimeout(e),e=setTimeout(t,300)};return window.addEventListener("resize",n),()=>{e&&clearTimeout(e),window.removeEventListener("resize",n)}},[a]),(0,t.useEffect)(()=>{let t;const e=()=>{t&&clearTimeout(t),t=setTimeout(()=>{if(u.current&&!u.current.isEmpty()){const t=u.current.toData(),e=u.current.getCanvas(),n=Math.max(window.devicePixelRatio||1,1);e.width=e.offsetWidth*n,e.height=e.offsetHeight*n,e.getContext("2d").scale(n,n),u.current.fromData(t)}},300)};return window.addEventListener("resize",e),()=>{t&&clearTimeout(t),window.removeEventListener("resize",e)}},[]);const S=(0,t.useCallback)(()=>{g(!1),y(!0)},[]),C=(0,t.useCallback)(()=>{if(y(!1),u.current){const t=u.current.toDataURL("image/png"),e=u.current.isEmpty();f(e),g(e),b.current=e?null:t,n({signature_type:"drawn",signature_data:e?null:t,canvas_dimensions:{width:w,height:s},timestamp:(new Date).toISOString()})}},[n,w,s]),P=(0,t.useCallback)(()=>{u.current&&(u.current.clear(),f(!0),g(!0),b.current=null,n({signature_type:"drawn",signature_data:null}))},[n]),E=((0,t.useCallback)(t=>(t.preventDefault(),!1),[]),(0,t.useMemo)(()=>{let t="nf-signature-canvas ninja-forms-field nf-element";return o?.element_class&&String(o.element_class).trim().length>0&&(t+=" "+String(o.element_class).trim()),t},[o?.element_class]));return(0,_.jsxs)("div",{className:"nf-signature-canvas-container",children:[(0,_.jsxs)("div",{ref:d,className:"nf-signature-canvas-wrapper",style:{width:`${a}px`,height:`${s}px`,maxWidth:"100%",position:"relative"},children:[(0,_.jsx)(v,{ref:u,canvasProps:{id:o?.id?`nf-field-${o.id}`:void 0,width:w,height:s,className:E,"data-react-managed":"true",style:{backgroundColor:c},tabIndex:0,"aria-label":(0,i.__)("Draw your signature here","ninja-forms"),"aria-labelledby":`nf-label-field-${o?.id}`,"aria-describedby":`nf-description-${o?.id} nf-error-${o?.id}`},penColor:l,velocityFilterWeight:.7,minWidth:.5,maxWidth:2.5,throttle:16,minDistance:5,dotSize:0,onBegin:S,onEnd:C}),p&&h&&(0,_.jsx)("div",{className:"nf-signature-canvas-placeholder",style:{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",pointerEvents:"none",color:"#767676",fontSize:"18px",fontStyle:"italic"},"aria-hidden":"true",children:o?.drawn_placeholder||(0,i.__)("Sign here","ninja-forms")})]}),(0,_.jsx)("div",{className:"nf-signature-controls",style:{marginTop:"10px"},children:(0,_.jsx)(e.Button,{onClick:P,variant:"secondary",disabled:h,className:"nf-signature-clear-button",children:(0,i.__)("Clear","ninja-forms")})}),(0,_.jsx)("div",{id:`nf-signature-instructions-${o?.id}`,className:"nf-field-help",children:(0,i.__)("Use your mouse, finger, or stylus to sign above.","ninja-forms")})]})},w=({onChange:e,value:n,fieldSettings:r,font:o="dancing-script"})=>{const[a,s]=(0,t.useState)(()=>n?.typed_name||""),[l,c]=(0,t.useState)(!1);(0,t.useEffect)(()=>{void 0===n?.typed_name||n.typed_name===a||l||s(n.typed_name||""),n||""===a||l||s("")},[n,n?.typed_name,a,l]);const u=(0,t.useCallback)(t=>{s(t),t&&""!==t.trim()?e({signature_type:"typed",typed_name:t,signature_font:o}):e({signature_type:"typed",typed_name:"",signature_font:o})},[e,o]),d=(0,t.useMemo)(()=>{const t={"dancing-script":'"Dancing Script", cursive',satisfy:'"Satisfy", cursive',cursive:"cursive"};return t[o]||t["dancing-script"]},[o]),h=(0,t.useMemo)(()=>{if(!a)return 32;const t=a.length;if(t<=15)return 48;if(t>=40)return 24;const e=48-24*(t-15)/25;return Math.round(e)},[a]),f=r?.id?`nf-field-${r.id}`:"nf-signature-typed-input",p=r?.id?`nf-signature-preview-${r.id}`:"nf-signature-preview",g=r?.id?`nf-field-${r.id}-signature`:"nf-signature-typed-input",m=r?.typed_placeholder||(0,i.__)("John Doe","ninja-forms"),v=r?.invalid||!1,y=(0,t.useMemo)(()=>{let t="ninja-forms-field nf-element";return r?.element_class&&String(r.element_class).trim().length>0&&(t+=" "+String(r.element_class).trim()),t},[r?.element_class]);return(0,_.jsxs)("div",{className:"nf-signature-typed-container",children:[(0,_.jsxs)("div",{className:"nf-signature-typed-input-wrapper",children:[(0,_.jsx)("label",{htmlFor:f,className:"nf-field-label",children:(0,i.__)("Type your full name","ninja-forms")}),(0,_.jsx)("input",{id:f,type:"text",value:a,name:g,onChange:t=>u(t.target.value),placeholder:m,onFocus:()=>c(!0),onBlur:()=>c(!1),className:y,"data-react-managed":"true",autoComplete:"on","aria-invalid":v?"true":"false","aria-describedby":`${p} nf-description-${r?.id||""} nf-error-${r?.id||""}`,"aria-labelledby":`nf-label-field-${r?.id||""}`,"aria-label":(0,i.__)("Type your full name to sign.","ninja-forms")})]}),(0,_.jsxs)("div",{className:"nf-signature-preview "+(l?"is-focused":""),children:[(0,_.jsx)("div",{className:"nf-signature-preview-label",children:(0,i.__)("Signature Preview:","ninja-forms")}),(0,_.jsx)("div",{className:"nf-signature-preview-text",style:{fontFamily:d,fontSize:`${h}px`,lineHeight:"1.2",color:"#000",textAlign:"center",padding:"20px",minHeight:"80px",display:"flex",alignItems:"center",justifyContent:"center",border:"1px solid #666",borderRadius:"4px",backgroundColor:"#fff",transition:"all 0.3s ease"},children:a||(0,_.jsx)("span",{style:{color:"#555",fontFamily:"inherit",fontSize:"24px"},children:(0,i.__)("Your signature will appear here","ninja-forms")})})]})]})},x=(0,t.memo)(({field:n,value:r,onChange:o})=>{const a=n||{},s=a.signature_method||"both",l=(0,t.useMemo)(()=>{if(!r||""===r)return null;if("string"==typeof r)try{return JSON.parse(r)}catch(t){return null}return r},[r]),[c,u]=(0,t.useState)(l?.signature_type||("typed"===s?"typed":"drawn")),{saveSignature:d,clearSignature:h,validateSignature:f}=(e=>{const[n,i]=(0,t.useState)(null);return{signatureData:n,saveSignature:(0,t.useCallback)(t=>{if(i(t),e&&t)try{localStorage.setItem(`nf_signature_${e}`,JSON.stringify(t))}catch(t){console.warn("Could not save signature to local storage:",t)}},[e]),clearSignature:(0,t.useCallback)(()=>{if(i(null),e)try{localStorage.removeItem(`nf_signature_${e}`)}catch(t){console.warn("Could not clear signature from local storage:",t)}},[e]),validateSignature:(0,t.useCallback)(t=>{if(!t||"object"!=typeof t)return!1;if(!t.signature_type||!["typed","drawn"].includes(t.signature_type))return!1;if("typed"===t.signature_type){if(!t.typed_name||0===t.typed_name.trim().length)return!1;if(t.typed_name.length>100)return!1;if(!/^[\p{L}\p{M}\s'-]+$/u.test(t.typed_name))return!1}if("drawn"===t.signature_type){if(!t.signature_data)return!1;if(!t.signature_data.match(/^data:image\/(png|jpeg);base64,/))return!1;if(t.signature_data.length>137e3)return!1;try{const e=t.signature_data.split(",")[1];e&&atob(e)}catch(t){return!1}}return!0},[])}})(a.id);(0,t.useEffect)(()=>{if(l&&a.id){const t={...l,field_id:a.id,timestamp:l.timestamp||(new Date).toISOString()};f(t)&&d(t)}else!l&&a.id&&h()},[a.id,l,f,d,h]),(0,t.useEffect)(()=>{"typed"===s?u("typed"):"drawn"===s&&u("drawn")},[s]);const p=(0,t.useCallback)(t=>{if("drawn"===t.signature_type&&!t.signature_data)return h(),void o("");if("typed"===t.signature_type&&(!t.typed_name||""===t.typed_name.trim()))return h(),void o("");const e={...t,field_id:a.id,timestamp:(new Date).toISOString()};f(e)&&(d(e),o(JSON.stringify(e)))},[a.id,f,d,h,o]),g=(0,t.useCallback)(t=>{u(t),h(),o("")},[h,o]),m=(0,t.useMemo)(()=>({onChange:p,value:l,fieldSettings:a}),[p,l,a]),v=(0,t.useMemo)(()=>{let t="nf-field-container nf-field-signature";return a?.container_class&&String(a.container_class).trim().length>0&&(t+=" "+String(a.container_class).trim()),t},[a?.container_class]);return(0,_.jsxs)("div",{className:v,children:["both"!==s?null:(0,_.jsxs)("div",{className:"nf-signature-method-selector",children:[(0,_.jsx)(e.Button,{className:"nf-signature-method-button "+("typed"===c?"is-active":""),onClick:()=>g("typed"),variant:"typed"===c?"primary":"secondary",children:(0,i.__)("Type Name","ninja-forms")}),(0,_.jsx)(e.Button,{className:"nf-signature-method-button "+("drawn"===c?"is-active":""),onClick:()=>g("drawn"),variant:"drawn"===c?"primary":"secondary",children:(0,i.__)("Draw Signature","ninja-forms")})]}),("drawn"===c||"drawn"===s&&"both"!==s)&&(0,_.jsx)(y,{...m,width:a.canvas_width||400,height:a.canvas_height||150,penColor:a.pen_color||"#000000",backgroundColor:a.background_color||"#ffffff"}),("typed"===c||"typed"===s&&"both"!==s)&&(0,_.jsx)(w,{...m,font:a.signature_font||"dancing-script"})]})}),b=()=>{if(void 0===window.Backbone||void 0===window.Marionette)return void setTimeout(b,100);const e=window.Marionette.Object.extend({initialize:function(t){this.model=t.model,this.el=t.el,this.mounted=!1,this.root=null,this.listenTo(this.model,"change:value",this.updateValue),this.listenTo(this.model,"change:errors",this.updateErrors),this.listenTo(this.model,"change:visible",this.updateVisibility),this.listenTo(this.model,"change:id",this.updateFieldId),this.render()},render:function(){if(!this.container){const e=document.createElement("div");e.className="nf-field-element";const n=this.el.querySelector(".nf-field-element");n&&n.parentNode?n.parentNode.replaceChild(e,n):this.el&&this.el.appendChild(e),this.container=e,this.root=(0,t.createRoot)(e)}const e={id:this.model.get("id"),key:this.model.get("key"),label:this.model.get("label"),required:this.model.get("required"),typed_placeholder:this.model.get("typed_placeholder"),drawn_placeholder:this.model.get("drawn_placeholder"),signature_method:this.model.get("signature_method")||"both",signature_font:this.model.get("signature_font")||"dancing-script",canvas_width:parseInt(this.model.get("canvas_width"))||400,canvas_height:parseInt(this.model.get("canvas_height"))||150,pen_color:this.model.get("pen_color")||"#000000",background_color:this.model.get("background_color")||"#ffffff",invalid:this.model.get("invalid")||!1,element_class:this.model.get("element_class")||"",container_class:this.model.get("container_class")||""},n=(0,t.createElement)(x,{field:e,value:this.model.get("value"),onChange:this.handleChange.bind(this)});this.root.render(n),this.mounted=!0},handleChange:function(t){if(this.model.set("value",t),t&&""!==t){var e=this.model.get("errors");if(e&&e.length>0){var n=e.pluck("id"),i=this.model.get("id");n.forEach(function(t){window.nfRadio.channel("fields").request("remove:error",i,t)})}}window.Backbone.Radio.channel("field-"+this.model.get("id")).trigger("change:field",this.model),window.Backbone.Radio.channel("field-"+this.model.get("id")).trigger("change:modelValue",this.model),window.Backbone.Radio.channel("form-"+this.model.get("formID")).trigger("change:fieldData",this.model),this.model.get("repeaterField")&&window.nfRadio.channel("field-repeater").trigger("set:value")},updateValue:function(){this.mounted&&this.container&&this.render()},updateErrors:function(){this.mounted&&this.container&&this.render()},updateVisibility:function(){this.el&&(this.model.get("visible")?this.el.style.display="":this.el.style.display="none")},updateFieldId:function(){this.mounted&&this.container&&this.render()},onDestroy:function(){this.root&&(this.root.unmount(),this.root=null),this.container=null}});window.nfRadio&&(window.nfRadio.channel("signature").on("render:view",function(t){new e({model:t.model,el:t.el})}),window.nfRadio.channel("signature").reply("validate:required",function(t,e){var n=e.get("value");if(!n||""===n)return!1;try{var i="string"==typeof n?JSON.parse(n):n;if("typed"===i.signature_type)return i.typed_name&&i.typed_name.trim().length>0;if("drawn"===i.signature_type)return i.signature_data&&i.signature_data.length>0}catch(t){return!1}return!1}),window.nfRadio.channel("signature").reply("validate:modelData",function(t){var e=t.get("value");if(!e||""===e)return!1;try{var n="string"==typeof e?JSON.parse(e):e;if("typed"===n.signature_type)return n.typed_name&&n.typed_name.trim().length>0;if("drawn"===n.signature_type)return n.signature_data&&n.signature_data.length>0}catch(t){return!1}return!1})),window.Marionette&&window.Marionette.Object&&window.nfRadio.channel("fields").trigger("register:controller","signature",e)};"loading"===document.readyState?document.addEventListener("DOMContentLoaded",b):b()})()})();