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