function b(t){return typeof t!="string"||t===""?(console.error("The namespace must be a non-empty string."),!1):/^[a-zA-Z][a-zA-Z0-9_.\-\/]*$/.test(t)?!0:(console.error("The namespace can only contain numbers, letters, dashes, periods, underscores and slashes."),!1)}function h(t){return typeof t!="string"||t===""?(console.error("The hook name must be a non-empty string."),!1):/^__/.test(t)?(console.error("The hook name cannot begin with `__`."),!1):/^[a-zA-Z][a-zA-Z0-9_.-]*$/.test(t)?!0:(console.error("The hook name can only contain numbers, letters, dashes, periods and underscores."),!1)}function _(t,o){return function(e,n,s,r=10){const u=t[o];if(!h(e)||!b(n))return;if(typeof s!="function"){console.error("The hook callback must be a function.");return}if(typeof r!="number"){console.error("If specified, the hook priority must be a number.");return}const c={callback:s,priority:r,namespace:n};if(u[e]){const l=u[e].handlers;let i;for(i=l.length;i>0&&!(r>=l[i-1].priority);i--);i===l.length?l[i]=c:l.splice(i,0,c),u.__current.forEach(a=>{a.name===e&&a.currentIndex>=i&&a.currentIndex++})}else u[e]={handlers:[c],runs:0};e!=="hookAdded"&&t.doAction("hookAdded",e,n,s,r)}}function d(t,o,f=!1){return function(n,s){const r=t[o];if(!h(n)||!f&&!b(s))return;if(!r[n])return 0;let u=0;if(f)u=r[n].handlers.length,r[n]={runs:r[n].runs,handlers:[]};else{const c=r[n].handlers;for(let l=c.length-1;l>=0;l--)c[l].namespace===s&&(c.splice(l,1),u++,r.__current.forEach(i=>{i.name===n&&i.currentIndex>=l&&i.currentIndex--}))}return n!=="hookRemoved"&&t.doAction("hookRemoved",n,s),u}}function p(t,o){return function(e,n){const s=t[o];return typeof n<"u"?e in s&&s[e].handlers.some(r=>r.namespace===n):e in s}}function y(t,o,f=!1){return function(n,...s){const r=t[o];r[n]||(r[n]={handlers:[],runs:0}),r[n].runs++;const u=r[n].handlers;if(!u||!u.length)return f?s[0]:void 0;const c={name:n,currentIndex:0};for(r.__current.push(c);c.currentIndex<u.length;){const i=u[c.currentIndex].callback.apply(null,s);f&&(s[0]=i),c.currentIndex++}if(r.__current.pop(),f)return s[0]}}function A(t,o){return function(){var s;var e;const n=t[o];return(e=(s=n.__current[n.__current.length-1])==null?void 0:s.name)!==null&&e!==void 0?e:null}}function H(t,o){return function(e){const n=t[o];return typeof e>"u"?typeof n.__current[0]<"u":n.__current[0]?e===n.__current[0].name:!1}}function g(t,o){return function(e){const n=t[o];if(h(e))return n[e]&&n[e].runs?n[e].runs:0}}class v{constructor(){this.actions=Object.create(null),this.actions.__current=[],this.filters=Object.create(null),this.filters.__current=[],this.addAction=_(this,"actions"),this.addFilter=_(this,"filters"),this.removeAction=d(this,"actions"),this.removeFilter=d(this,"filters"),this.hasAction=p(this,"actions"),this.hasFilter=p(this,"filters"),this.removeAllActions=d(this,"actions",!0),this.removeAllFilters=d(this,"filters",!0),this.doAction=y(this,"actions"),this.applyFilters=y(this,"filters",!0),this.currentAction=A(this,"actions"),this.currentFilter=A(this,"filters"),this.doingAction=H(this,"actions"),this.doingFilter=H(this,"filters"),this.didAction=g(this,"actions"),this.didFilter=g(this,"filters")}}function x(){return new v}const S=x();export{S as d};
