(function($,p){typeof exports=="object"&&typeof module<"u"?p(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],p):($=typeof globalThis<"u"?globalThis:$||self,p($.VueSimpleAclNext={},$.Vue))})(this,function($,p){"use strict";function R(e){let l=null;const d=/\(([a-z0-9 ,$_+*\-/]+)\)/im,t=e.toString().match(d);if(t&&Array.isArray(t)&&t[0]){let u=t[0];u=u.replace(/\(|\)|[ ]/g,"");const a=u.split(",");a.length>0&&(l=a)}return l}function C(e){return typeof e!="string"?"":e.charAt(0).toUpperCase()+e.slice(1)}let A=p.ref(null);const v=p.reactive({registeredRules:{},options:{}});function j(e){p.isRef(e.user)?A=e.user:O(e.user)?A.value=e.user():A.value=e.user,e.rules&&typeof e.rules=="function"&&e.rules(),v.options=e}function L(e,l){Object.prototype.hasOwnProperty.call(v.registeredRules,e)?console.warn(`:::VueSimpleACL::: Duplicate ACL Rule '${e}' defined. Only the first defined rule will be evaluated.`):v.registeredRules[e]=l}function H(e,l){typeof e=="string"?L(e,l):typeof e=="object"&&Array.isArray(e)&&Object.values(e).forEach(d=>{L(d,l)})}function M(e,l,d){try{return typeof e=="function"?typeof d=="object"&&!Array.isArray(d)?e(A.value,d):typeof d=="object"&&Array.isArray(d)?e(A.value,...d):e(A.value):!1}catch(i){const t=R(e);let u=null;t&&Array.isArray(t)&&(t.shift(),u=t.join(", "));let a=`:::VueSimpleACL::: The defined ACL Rule for "${l}" require some argument(s) or data object to be specified for matching.`;return a+=` Check the file containing your defineAclRules((setRule) => {...}); declarations`,a+=` Examples:`,t&&t.length<=0?(a+=` v-can:${l}`,a+=` v-can="'${l}'"`,a+=` $can('${l}')`):t&&t.length===1?(a+=` v-can:${l}="${u}"`,a+=` v-can="'${l}', ${u}"`,a+=` $can('${l}', ${u})`):(a+=` v-can:${l}="[${u}]"`,a+=` v-can="'${l}', [${u}]"`,a+=` $can('${l}', [${u}])`),console.error(a),console.error(i),!1}}function b({abilities:e,args:l,any:d=!1}){if(e&&typeof e=="string"){if(Object.prototype.hasOwnProperty.call(v.registeredRules,e)){const i=v.registeredRules[e];return M(i,e,l)}}else if(typeof e=="object"&&Array.isArray(e)){let i=!1,t=!1,u=0,a=0;return e.forEach(f=>{if(Object.prototype.hasOwnProperty.call(v.registeredRules,f.abilities)){const m=v.registeredRules[f.abilities];t=M(m,f.abilities,f.args),t&&a++,d===!0&&t&&(i=!0),u++}}),u>0&&u===a&&(i=!0),i}return!1}function S({abilities:e,args:l,any:d=!1}){const i=e,t=l,u=d;let a=!1;if(i)t?a=b({abilities:i,args:t}):a=b({abilities:i});else if(t&&typeof t=="string")a=b({abilities:t});else if(t&&typeof t=="object")if((Array.isArray(t)?t.length:Object.keys(t).length)===2&&typeof t[0]=="string"&&typeof t[1]=="object"&&!Array.isArray(t[1]))a=b({abilities:t[0],args:t[1]});else{const m=[],r=[];t.forEach(n=>{if(n&&typeof n=="string")m.push({abilities:n});else if(n&&typeof n=="object"){let s=null;const c=[];n.forEach(o=>{o&&!s&&typeof o=="string"?s=o:c.push(o)}),s&&m.push({abilities:s,args:c})}}),a=b({abilities:m,args:r,any:u})}return a}function N({abilities:e,args:l,any:d=!1}){return e&&typeof e=="string"?S({abilities:e,args:l,any:d}):typeof e=="object"?S({abilities:null,args:e,any:d}):(console.warn(":::VueSimpleACL::: Invalid ACL arguments specified."),!1)}function g(e,l){return N({abilities:e,args:l,any:!1})}function y(e,l){return!N({abilities:e,args:l,any:!1})}function h(e,l){return N({abilities:e,args:l,any:!0})}function O(e){return typeof e=="function"&&e()instanceof Promise}function w(e,l){const i={...{user:Object.create(null),rules:null,router:null,onDeniedRoute:"/",directiveName:"can",helperName:"$can",enableSematicAlias:!0},...l};i.directiveName&&i.directiveName.startsWith("v-")&&(i.directiveName=i.directiveName.substring(2,i.directiveName.length)),i.helperName&&i.helperName.charAt(0)!=="$"&&(i.helperName=`$${i.helperName}`),O(i.user)||j(i);const t=(f,m)=>{const r=m.arg,n=m.value,s=m.modifiers,c=!!s.any,o=!!s.not,P=!!s.readonly,T=!!(s.disable||s.disabled),I=!!(s.hide||s.hidden);S({abilities:r,args:n,any:c})?o&&(f.style.display="none"):o||(T?f.disabled=!0:P?f.readOnly=!0:f.style.display="none")},u=(f,m)=>{f.directive(`${m}`,{mounted(r,n){t(r,n)},updated(r,n){t(r,n)}})},a=(f,m,r)=>{r?(f.config.globalProperties.$acl||(f.config.globalProperties.$acl={}),f.config.globalProperties.$acl[m]=(n,s)=>g(n,s),f.config.globalProperties.$acl[`all${C(m)}`]=(n,s)=>g(n,s),f.config.globalProperties.$acl[`not${C(m)}`]=(n,s)=>y(n,s),f.config.globalProperties.$acl[`any${C(m)}`]=(n,s)=>h(n,s)):(f.config.globalProperties[m]=(n,s)=>g(n,s),f.config.globalProperties[m].all=(n,s)=>g(n,s),f.config.globalProperties[m].not=(n,s)=>y(n,s),f.config.globalProperties[m].any=(n,s)=>h(n,s))};if(u(e,`${i.directiveName}`),i.enableSematicAlias&&(u(e,"permission"),u(e,"permissions"),u(e,"role"),u(e,"roles"),u(e,"role-or-permission"),u(e,"role-or-permissions")),a(e,`${i.helperName}`,!1),i.enableSematicAlias&&(a(e,"can",!0),a(e,"permission",!0),a(e,"permissions",!0),a(e,"role",!0),a(e,"roles",!0),a(e,"roleOrPermission",!0),a(e,"roleOrPermissions",!0),e.config.globalProperties.$acl||(e.config.globalProperties.$acl={}),e.config.globalProperties.$acl.user=A,e.config.globalProperties.$acl.getUser=()=>A.value),i.router){const f=(r,n,s,c)=>{if(c)s();else{let o=i.onDeniedRoute;r.meta&&r.meta.onDeniedRoute&&(o=r.meta.onDeniedRoute),s(typeof o=="object"?o:o==="$from"?n:{path:`${o}`,replace:!0})}},m=(r,n,s)=>{if(r.meta&&(r.meta.can||r.meta.permission||r.meta.role||r.meta.roleOrPermission)){const c=r.meta.can||r.meta.permission||r.meta.role||r.meta.roleOrPermission;let o=!1;if(typeof c=="function"){const P=R(c);Array.isArray(P)&&P.length===4?o=c(r,n,g,A.value):o=c(r,n,g)}else o=g(c);f(r,n,s,o)}else if(r.meta&&(r.meta.canAll||r.meta.allCan||r.meta.allPermission||r.meta.allRole||r.meta.allRoleOrPermission)){const c=r.meta.canAll||r.meta.allCan||r.meta.allPermission||r.meta.allRole||r.meta.allRoleOrPermission;let o=!1;if(typeof c=="function"){const P=R(c);Array.isArray(P)&&P.length===4?o=c(r,n,g,A.value):o=c(r,n,g)}else o=g(c);f(r,n,s,o)}else if(r.meta&&(r.meta.cannot||r.meta.canNot||r.meta.notCan||r.meta.notPermission||r.meta.notRole||r.meta.notRoleOrPermission)){const c=r.meta.cannot||r.meta.canNot||r.meta.notCan||r.meta.notPermission||r.meta.notRole||r.meta.notRoleOrPermission;let o=!1;if(typeof c=="function"){const P=R(c);Array.isArray(P)&&P.length===4?o=c(r,n,y,A.value):o=c(r,n,y)}else o=y(c);f(r,n,s,o)}else if(r.meta&&(r.meta.canAny||r.meta.anyCan||r.meta.anyPermission||r.meta.anyRole||r.meta.anyRoleOrPermission)){const c=r.meta.canAny||r.meta.anyCan||r.meta.anyPermission||r.meta.anyRole||r.meta.anyRoleOrPermission;let o=!1;if(typeof c=="function"){const P=R(c);Array.isArray(P)&&P.length===4?o=c(r,n,h,A.value):o=c(r,n,h)}else o=h(c);f(r,n,s,o)}else s()};i.router.beforeEach((r,n,s)=>{O(i.user)?i.user().then(c=>{i.user=c,j(i),m(r,n,s)}).catch(()=>{console.warn(":::VueSimpleACL::: Error while processing/retrieving 'user' data with the Asynchronous function.")}):m(r,n,s)})}else O(i.user)&&console.error(":::VueSimpleACL::: Instance of vue-router is required to define 'user' retrieved from a promise or Asynchronous function.")}function V(e){return{install:(l,d={})=>{w(l,{...d,...e})}}}function E(e){typeof e=="function"&&e(H)}function D(){const e={};return e.user=A,e.getUser=()=>A.value,e.can=g,e.can.not=y,e.can.any=h,e.notCan=y,e.canNot=y,e.cannot=y,e.anyCan=h,e.permission=g,e.allPermission=g,e.notPermission=y,e.anyPermission=h,e.permission.not=y,e.permission.any=h,e.role=g,e.allRole=g,e.notRole=y,e.anyRole=h,e.role.not=y,e.role.any=h,e.roleOrPermission=g,e.allRoleOrPermission=g,e.notRoleOrPermission=y,e.anyRoleOrPermission=h,e.roleOrPermission.not=y,e.roleOrPermission.any=h,p.reactive(e)}const k={install:(e,l)=>w(e,l)};$.createAcl=V,$.default=k,$.defineAclRules=E,$.useAcl=D,Object.defineProperties($,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});