!function(t,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r(require("is-url"),require("nanoid/non-secure"),require("is-plain-object")):"function"==typeof define&&define.amd?define(["is-url","nanoid/non-secure","is-plain-object"],r):(t=t||self).Formulario=r(t.isUrl,t.nanoid,t.isPlainObject)}(this,(function(t,r,e){"use strict";t=t&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t,r=r&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r,e=e&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e;var i=function(t,r){return{classification:t,component:"FormularioInput"+(r||t[0].toUpperCase()+t.substr(1))}},o=Object.assign({},["text","email","number","color","date","hidden","month","password","search","tel","time","url","week","datetime-local"].reduce((function(t,r){var e;return Object.assign({},t,((e={})[r]=i("text"),e))}),{}),{range:i("slider"),textarea:i("textarea","TextArea"),checkbox:i("box"),radio:i("box"),submit:i("button"),button:i("button"),select:i("select"),file:i("file"),image:i("file"),group:i("group")}),n=function(t,r,e){void 0===e&&(e={}),this.input=t,this.fileList=t.files,this.files=[],this.options=Object.assign({},{mimes:{}},e),this.results=!1,this.context=r,Array.isArray(this.fileList)?this.rehydrateFileList(this.fileList):this.addFileList(this.fileList)};function s(t,r){if(t===r)return!0;if(!t||!r)return!1;var e=Object.keys(t),i=Object.keys(r),o=e.length;if(i.length!==o)return!1;if(t instanceof Date&&r instanceof Date)return t.getTime()===r.getTime();if(0===o)return t===r;for(var n=0;n=100&&(r.complete||(r.justFinished=!0,setTimeout((function(){r.justFinished=!1}),t.options.uploadJustCompleteDuration)),r.complete=!0)}),(function(t){r.progress=0,r.error=t,r.complete=!0}),t.options)}))).then((function(e){t.results=e,r(e)})).catch((function(t){throw new Error(t)}))}))},n.prototype.removeFile=function(t){if(this.files=this.files.filter((function(r){return r.uuid!==t})),this.context.performValidation(),window&&this.fileList instanceof FileList){var r=new DataTransfer;this.files.map((function(t){return r.items.add(t.file)})),this.fileList=r.files,this.input.files=this.fileList}},n.prototype.loadPreviews=function(){this.files.map((function(t){if(!t.previewData&&window&&window.FileReader&&/^image\//.test(t.file.type)){var r=new FileReader;r.onload=function(r){return Object.assign(t,{previewData:r.target.result})},r.readAsDataURL(t.file)}}))},n.prototype.getFileList=function(){return this.fileList},n.prototype.getFiles=function(){return this.files},n.prototype.toString=function(){var t=this.files.length?this.files.length+" files":"empty";return this.results?JSON.stringify(this.results,null," "):"FileUpload("+t+")"};var p={accepted:function(t){var r=t.value;return Promise.resolve(["yes","on","1",1,!0,"true"].includes(r))},after:function(t,r){var e=t.value;void 0===r&&(r=!1);var i=Date.parse(r||new Date),o=Date.parse(e);return Promise.resolve(!isNaN(o)&&o>i)},alpha:function(t,r){var e=t.value;void 0===r&&(r="default");var i={default:/^[a-zA-ZÀ-ÖØ-öø-ÿ]+$/,latin:/^[a-zA-Z]+$/},o=i.hasOwnProperty(r)?r:"default";return Promise.resolve(i[o].test(e))},alphanumeric:function(t,r){var e=t.value;void 0===r&&(r="default");var i={default:/^[a-zA-Z0-9À-ÖØ-öø-ÿ]+$/,latin:/^[a-zA-Z0-9]+$/},o=i.hasOwnProperty(r)?r:"default";return Promise.resolve(i[o].test(e))},before:function(t,r){var e=t.value;void 0===r&&(r=!1);var i=Date.parse(r||new Date),o=Date.parse(e);return Promise.resolve(!isNaN(o)&&or&&or&&o.length()\[\]\.,;:\s@\"]+(\.[^<>()\[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/i.test(r))},endsWith:function(t){for(var r=t.value,e=[],i=arguments.length-1;i-- >0;)e[i]=arguments[i+1];return r?Promise.resolve("string"==typeof r&&e.length?void 0!==e.find((function(t){return r.endsWith(t)})):"string"==typeof r&&0===e.length):Promise.resolve((function(){return!0}))},in:function(t){for(var r=t.value,e=[],i=arguments.length-1;i-- >0;)e[i]=arguments[i+1];return Promise.resolve(void 0!==e.find((function(t){return"object"==typeof t?s(t,r):t===r})))},matches:function(t){for(var r=t.value,e=[],i=arguments.length-1;i-- >0;)e[i]=arguments[i+1];return Promise.resolve(!!e.find((function(t){return"string"==typeof t&&"/"===t.substr(0,1)&&"/"===t.substr(-1)&&(t=new RegExp(t.substr(1,t.length-2))),t instanceof RegExp?t.test(r):t===r})))},mime:function(t){for(var r=t.value,e=[],i=arguments.length-1;i-- >0;)e[i]=arguments[i+1];return Promise.resolve(function(){if(r instanceof n)for(var t=r.getFiles(),i=0;i=r):!isNaN(i)&&"length"!==e||"value"===e?(i=isNaN(i)?i:Number(i))>=r:("string"==typeof i||"length"===e)&&(i=isNaN(i)?i:i.toString()).length>=r)},max:function(t,r,e){var i=t.value;return void 0===r&&(r=10),Promise.resolve(Array.isArray(i)?(r=isNaN(r)?r:Number(r),i.length<=r):!isNaN(i)&&"length"!==e||"value"===e?(i=isNaN(i)?i:Number(i))<=r:("string"==typeof i||"length"===e)&&(i=isNaN(i)?i:i.toString()).length<=r)},not:function(t){for(var r=t.value,e=[],i=arguments.length-1;i-- >0;)e[i]=arguments[i+1];return Promise.resolve(void 0===e.find((function(t){return"object"==typeof t?s(t,r):t===r})))},number:function(t){var r=t.value;return Promise.resolve(!isNaN(r))},required:function(t,r){var e=t.value;return void 0===r&&(r=!0),Promise.resolve(!(r&&!["no","false"].includes(r))||(Array.isArray(e)?!!e.length:e instanceof n?e.getFiles().length>0:"string"==typeof e?!!e:"object"!=typeof e||!!e&&!!Object.keys(e).length))},startsWith:function(t){for(var r=t.value,e=[],i=arguments.length-1;i-- >0;)e[i]=arguments[i+1];return r?Promise.resolve("string"==typeof r&&e.length?void 0!==e.find((function(t){return r.startsWith(t)})):"string"==typeof r&&0===e.length):Promise.resolve((function(){return!0}))},url:function(r){var e=r.value;return Promise.resolve(t(e))},bail:function(){return Promise.resolve(!0)}},m="image/",v={csv:"text/csv",gif:m+"gif",jpg:m+"jpeg",jpeg:m+"jpeg",png:m+"png",pdf:"application/pdf",svg:m+"svg+xml"},g={default:function(t,r){return t.$t("validation.default",r)},accepted:function(t,r){return t.$t("validation.accepted",r)},after:function(t,r){return Array.isArray(r.args)&&r.args.length?(r.compare=r.args[0],t.$t("validation.after.compare",r)):t.$t("validation.after.default",r)},alpha:function(t,r){return t.$t("validation.alpha",r)},alphanumeric:function(t,r){return t.$t("validation.alphanumeric",r)},before:function(t,r){return Array.isArray(r.args)&&r.args.length?(r.compare=r.args[0],t.$t("validation.before.compare",r)):t.$t("validation.before.default",r)},between:function(t,r){r.from=r.args[0],r.to=r.args[1];var e=!(!Array.isArray(r.args)||!r.args[2])&&r.args[2];return!isNaN(value)&&"length"!==e||"value"===e?t.$t("validation.between.force",r):t.$t("validation.between.default",r)},confirm:function(t,r){return t.$t("validation.confirm",r)},date:function(t,r){return Array.isArray(r.args)&&r.args.length?(r.format=r.args[0],t.$t("validation.date.format",r)):t.$t("validation.date.default",r)},email:function(t,r){return t.$t("validation.email.default",r)},endsWith:function(t,r){return t.$t("validation.endsWith.default",r)},in:function(t,r){return"string"==typeof r.value&&r.value?t.$t("validation.in.string",r):t.$t("validation.in.default",r)},matches:function(t,r){return t.$t("validation.matches.default",r)},max:function(t,r){if(r.maximum=r.args[0],Array.isArray(r.value))return t.$tc("validation.max.array",r.maximum,r);var e=!(!Array.isArray(r.args)||!r.args[1])&&r.args[1];return!isNaN(r.value)&&"length"!==e||"value"===e?t.$tc("validation.max.force",r.maximum,r):t.$tc("validation.max.default",r.maximum,r)},mime:function(t,r){return r.types=r.args[0],r.types?t.$t("validation.mime.default",r):t.$t("validation.mime.no_formats_allowed",r)},min:function(t,r){if(r.minimum=r.args[0],Array.isArray(r.value))return t.$tc("validation.min.array",r.minimum,r);var e=!(!Array.isArray(r.args)||!r.args[1])&&r.args[1];return!isNaN(r.value)&&"length"!==e||"value"===e?t.$tc("validation.min.force",r.minimum,r):t.$tc("validation.min.default",r.minimum,r)},not:function(t,r){return t.$t("validation.not.default",r)},number:function(t,r){return t.$t("validation.number.default",r)},required:function(t,r){return t.$t("validation.required.default",r)},startsWith:function(t,r){return t.$t("validation.startsWith.default",r)},url:function(t,r){return t.$t("validation.url.default",r)}};function y(t){t.extend({validationMessages:g})}function b(t,r,e,i){return new Promise((function(e,o){var n=(i.fauxUploaderDuration||2e3)*(.5+Math.random()),s=performance.now(),a=function(){return setTimeout((function(){var i=performance.now()-s,o=Math.min(100,Math.round(i/n*100));if(r(o),o>=100)return e({url:"http://via.placeholder.com/350x150.png",name:t.name});a()}),20)};a()}))}function E(t,r){var e={};for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&-1===r.indexOf(i)&&(e[i]=t[i]);return e}var x=function(t){this.registry=new Map,this.ctx=t};x.prototype.add=function(t,r){return this.registry.set(t,r),this},x.prototype.remove=function(t){this.registry.delete(t);var r=this.ctx.proxy,e=(r[t],E(r,[String(t)]));return this.ctx.proxy=e,this},x.prototype.has=function(t){return this.registry.has(t)},x.prototype.get=function(t){return this.registry.get(t)},x.prototype.map=function(t){var r={};return this.registry.forEach((function(e,i){var o;return Object.assign(r,((o={})[i]=t(e,i),o))})),r},x.prototype.keys=function(){return Array.from(this.registry.keys())},x.prototype.register=function(t,r){if(this.registry.has(t))return!1;this.registry.set(t,r);var e=c(r.$options.propsData,"formularioValue"),i=c(r.$options.propsData,"value");!e&&this.ctx.hasInitialValue&&void 0!==d(this.ctx.initialValues,t)?r.context.model=d(this.ctx.initialValues,t):!e&&!i||s(r.proxy,d(this.ctx.initialValues,t))||this.ctx.setFieldValue(t,r.proxy),this.childrenShouldShowErrors&&(r.formShouldShowErrors=!0)},x.prototype.reduce=function(t,r){return this.registry.forEach((function(e,i){r=t(r,e,i)})),r},x.prototype.dataProps=function(){var t=this;return{proxy:{},registry:this,register:this.register.bind(this),deregister:function(r){return t.remove(r)},childrenShouldShowErrors:!1}};var V=function(t){this.form=t};function w(t,r,e,i,o,n,s,a,u,l){"boolean"!=typeof s&&(u=a,a=s,s=!1);var f,h="function"==typeof e?e.options:e;if(t&&t.render&&(h.render=t.render,h.staticRenderFns=t.staticRenderFns,h._compiled=!0,o&&(h.functional=!0)),i&&(h._scopeId=i),n?(f=function(t){(t=t||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext)||"undefined"==typeof __VUE_SSR_CONTEXT__||(t=__VUE_SSR_CONTEXT__),r&&r.call(this,u(t)),t&&t._registeredComponents&&t._registeredComponents.add(n)},h._ssrRegister=f):r&&(f=s?function(t){r.call(this,l(t,this.$root.$options.shadowRoot))}:function(t){r.call(this,a(t))}),f)if(h.functional){var c=h.render;h.render=function(t,r){return f.call(r),c(t,r)}}else{var d=h.beforeCreate;h.beforeCreate=d?[].concat(d,f):[f]}return e}V.prototype.hasValidationErrors=function(){return this.form.hasValidationErrors()},V.prototype.values=function(){var t=this;return new Promise((function(r,e){var i=[],o=function t(r){if("object"!=typeof r)return r;var e=Array.isArray(r)?[]:{};for(var i in r)r[i]instanceof n||h(r[i])?e[i]=r[i]:e[i]=t(r[i]);return e}(t.form.proxy),s=function(r){"object"==typeof t.form.proxy[r]&&t.form.proxy[r]instanceof n&&i.push(t.form.proxy[r].upload().then((function(t){var e;return Object.assign(o,((e={})[r]=t,e))})))};for(var a in o)s(a);Promise.all(i).then((function(){return r(o)})).catch((function(t){return e(t)}))}))};var O={provide:function(){return Object.assign({},{formularioSetter:(t=this).setFieldValue,formularioRegister:t.register,formularioDeregister:t.deregister,getFormValues:t.getFormValues},{observeErrors:this.addErrorObserver,removeErrorObserver:this.removeErrorObserver,formularioFieldValidation:this.formularioFieldValidation,path:""});var t},name:"FormularioForm",model:{prop:"formularioValue",event:"input"},props:{name:{type:[String,Boolean],default:!1},formularioValue:{type:Object,default:function(){return{}}},values:{type:[Object,Boolean],default:!1},errors:{type:[Object,Boolean],default:!1},formErrors:{type:Array,default:function(){return[]}}},data:function(){return Object.assign({},new x(this).dataProps(),{formShouldShowErrors:!1,errorObservers:[],namedErrors:[],namedFieldErrors:{}})},computed:Object.assign({},{hasInitialValue:function(){return this.formularioValue&&"object"==typeof this.formularioValue||this.values&&"object"==typeof this.values||this.isGrouping&&"object"==typeof this.context.model[this.index]},isVmodeled:function(){return!!(this.$options.propsData.hasOwnProperty("formularioValue")&&this._events&&Array.isArray(this._events.input)&&this._events.input.length)},initialValues:function(){return c(this.$options.propsData,"formularioValue")&&"object"==typeof this.formularioValue?Object.assign({},this.formularioValue):c(this.$options.propsData,"values")&&"object"==typeof this.values?Object.assign({},this.values):this.isGrouping&&"object"==typeof this.context.model[this.index]?this.context.model[this.index]:{}}},{classes:function(){var t={"formulario-form":!0};return this.name&&(t["formulario-form--"+this.name]=!0),t},mergedFormErrors:function(){return this.formErrors.concat(this.namedErrors)},mergedFieldErrors:function(){var t={};if(this.errors)for(var r in this.errors)t[r]=u(this.errors[r]);for(var e in this.namedFieldErrors)t[e]=u(this.namedFieldErrors[e]);return t},hasFormErrorObservers:function(){return!!this.errorObservers.filter((function(t){return"form"===t.type})).length}}),watch:{formularioValue:{handler:function(t){this.isVmodeled&&t&&"object"==typeof t&&this.setValues(t)},deep:!0},mergedFormErrors:function(t){this.errorObservers.filter((function(t){return"form"===t.type})).forEach((function(r){return r.callback(t)}))},mergedFieldErrors:{handler:function(t){this.errorObservers.filter((function(t){return"input"===t.type})).forEach((function(r){return r.callback(t[r.field]||[])}))},immediate:!0}},created:function(){this.$formulario.register(this),this.applyInitialValues()},destroyed:function(){this.$formulario.deregister(this)},methods:Object.assign({},function(t){void 0===t&&(t=[]);var r={applyInitialValues:function(){this.hasInitialValue&&(this.proxy=this.initialValues)},setFieldValue:function(t,r){if(void 0===r){var e=this.proxy,i=(e[t],E(e,[String(t)]));this.proxy=i}else!function(t,r,e){for(var i=r.split("."),o=t,n=0;n=0){var i=t.splice(0,e+1).slice(0,-1);i.length&&r.push(i),t.map((function(t){return r.push(Object.defineProperty([t],"bail",{value:!0}))}))}else r.push(t);return r.reduce((function(t,r){var e=function(t,r){if(void 0===r&&(r=!1),t.length<2)return Object.defineProperty([t],"bail",{value:r});var i=[],o=t.findIndex((function(t){return"^"===t[3]}));if(o>=0){var n=t.splice(0,o);n.length&&i.push.apply(i,e(n,r)),i.push(Object.defineProperty([t.shift()],"bail",{value:!0})),t.length&&i.push.apply(i,e(t,r))}else i.push(t);return i};return t.concat(e(r))}),[])}(t))}))},didValidate:function(t){var r=!s(t,this.validationErrors);if(this.validationErrors=t,r){var e=this.getErrorObject();this.$emit("validation",e),this.formularioFieldValidation&&"function"==typeof this.formularioFieldValidation&&this.formularioFieldValidation(e)}},getMessageObject:function(t,r){var e={args:r,name:this.mergedValidationName,value:this.context.model,vm:this,formValues:this.getFormValues()};return{message:this.getMessageFunc(t)(e),rule:t,context:e}},getMessageFunc:function(t){var r=this;if(t=a(t),this.messages&&void 0!==this.messages[t])switch(typeof this.messages[t]){case"function":return this.messages[t];case"string":case"boolean":return function(){return r.messages[t]}}return function(e){return r.$formulario.validationMessage(t,e,r)}},hasValidationErrors:function(){var t=this;return new Promise((function(r){t.$nextTick((function(){t.pendingValidation.then((function(){return r(!!t.validationErrors.length)}))}))}))},getValidationErrors:function(){var t=this;return new Promise((function(r){t.$nextTick((function(){return t.pendingValidation.then((function(){return r(t.getErrorObject())}))}))}))},getErrorObject:function(){return{name:this.context.nameOrFallback||this.context.name,errors:this.validationErrors.filter((function(t){return"object"==typeof t})),hasErrors:!!this.validationErrors.length}},setErrors:function(t){this.localErrors=u(t)},registerRule:function(t,r,e,i){void 0===i&&(i=null),this.ruleRegistry.some((function(t){return t[2]===e}))||(this.ruleRegistry.push([t,r,e]),null!==i&&(this.messageRegistry[e]=i))},removeRule:function(t){var r=this.ruleRegistry.findIndex((function(r){return r[2]===t}));r>=0&&(this.ruleRegistry.splice(r,1),delete this.messageRegistry[t])}}},_=function(){var t=this,r=t.$createElement;return(t._self._c||r)("div",{staticClass:"formulario-input",attrs:{"data-has-errors":t.hasErrors,"data-is-showing-errors":t.hasVisibleErrors,"data-type":t.type}},[t._t("default",null,{id:t.id,context:t.context,errors:t.errors,validationErrors:t.validationErrors})],2)};_._withStripped=!0;var D=w({render:_,staticRenderFns:[]},void 0,R,void 0,!1,void 0,!1,void 0,void 0,void 0),U={name:"FormularioGrouping",props:{name:{type:String,required:!0},isArrayItem:{type:Boolean,default:!1}},provide:function(){return{path:this.groupPath}},inject:["path"],computed:{groupPath:function(){return this.isArrayItem?this.path+"["+this.name+"]":""===this.path?this.name:this.path+"."+this.name}}},k=function(){var t=this.$createElement;return(this._self._c||t)("div",{staticClass:"formulario-group",attrs:{"data-type":"group"}},[this._t("default")],2)};k._withStripped=!0;var I=w({render:k,staticRenderFns:[]},void 0,U,void 0,!1,void 0,!1,void 0,void 0,void 0),B=function(){this.options={},this.defaults={components:{FormularioForm:F,FormularioInput:D,FormularioGrouping:I},library:o,rules:p,mimes:v,locale:!1,uploader:b,uploadUrl:!1,fileUrlKey:"url",uploadJustCompleteDuration:1e3,errorHandler:function(t){return t},plugins:[y],validationMessages:{},idPrefix:"formulario-"},this.registry=new Map,this.idRegistry={}};return B.prototype.install=function(t,r){var e=this;t.prototype.$formulario=this,this.options=this.defaults;var i=this.defaults.plugins;for(var o in r&&Array.isArray(r.plugins)&&r.plugins.length&&(i=i.concat(r.plugins)),i.forEach((function(t){return"function"==typeof t?t(e):null})),this.extend(r||{}),this.options.components)t.component(o,this.options.components[o])},B.prototype.nextId=function(t){var r=!(!t.$route||!t.$route.path)&&t.$route.path?t.$route.path.replace(/[/\\.\s]/g,"-"):"global";return Object.prototype.hasOwnProperty.call(this.idRegistry,r)||(this.idRegistry[r]=0),""+this.options.idPrefix+r+"-"+ ++this.idRegistry[r]},B.prototype.extend=function(t){if("object"==typeof t)return this.options=this.merge(this.options,t),this;throw new Error("VueFormulario extend() should be passed an object (was "+typeof t+")")},B.prototype.merge=function(t,r,i){void 0===i&&(i=!0);var o={};for(var n in t)r.hasOwnProperty(n)?e(r[n])&&e(t[n])?o[n]=this.merge(t[n],r[n],i):i&&Array.isArray(t[n])&&Array.isArray(r[n])?o[n]=t[n].concat(r[n]):o[n]=r[n]:o[n]=t[n];for(var s in r)o.hasOwnProperty(s)||(o[s]=r[s]);return o},B.prototype.classify=function(t){return this.options.library.hasOwnProperty(t)?this.options.library[t].classification:"unknown"},B.prototype.component=function(t){return!!this.options.library.hasOwnProperty(t)&&this.options.library[t].component},B.prototype.rules=function(t){return void 0===t&&(t={}),Object.assign({},this.options.rules,t)},B.prototype.validationMessage=function(t,r,e){return this.options.validationMessages.hasOwnProperty(t)?this.options.validationMessages[t](e,r):this.options.validationMessages.default(e,r)},B.prototype.register=function(t){"FormularioForm"===t.$options.name&&t.name&&this.registry.set(t.name,t)},B.prototype.deregister=function(t){"FormularioForm"===t.$options.name&&t.name&&this.registry.has(t.name)&&this.registry.delete(t.name)},B.prototype.handle=function(t,r,e){void 0===e&&(e=!1);var i=e?t:this.options.errorHandler(t,r);return r&&this.registry.has(r)&&this.registry.get(r).applyErrors({formErrors:u(i.formErrors),inputErrors:i.inputErrors||{}}),i},B.prototype.reset=function(t,r){void 0===r&&(r={}),this.resetValidation(t),this.setValues(t,r)},B.prototype.resetValidation=function(t){var r=this.registry.get(t);r.hideErrors(t),r.namedErrors=[],r.namedFieldErrors={}},B.prototype.setValues=function(t,r){r&&!Array.isArray(r)&&"object"==typeof r&&this.registry.get(t).setValues(Object.assign({},r))},B.prototype.getUploader=function(){return this.options.uploader||!1},B.prototype.getUploadUrl=function(){return this.options.uploadUrl||!1},B.prototype.getFileUrlKey=function(){return this.options.fileUrlKey||"url"},B.prototype.createUpload=function(t,r){return new n(t,r,this.options)},new B}));