(function(a,c){typeof exports=="object"&&typeof module<"u"?c(exports):typeof define=="function"&&define.amd?define(["exports"],c):(a=typeof globalThis<"u"?globalThis:a||self,c(a.index={}))})(this,function(a){"use strict";var _r=Object.defineProperty;var gr=(a,c,h)=>c in a?_r(a,c,{enumerable:!0,configurable:!0,writable:!0,value:h}):a[c]=h;var b=(a,c,h)=>(gr(a,typeof c!="symbol"?c+"":c,h),h);class c{static debug(r){this._logLevel>=4&&console.debug(this._prefix+r)}static info(r,t=void 0){this._logLevel>=3&&console.info(this._prefix+r,t)}static warn(r){this._logLevel>=1&&console.warn(this._prefix+r)}static error(r,t=!0){if(this._logLevel>=0){if(t)throw new Error(this._prefix+r);console.error(this._prefix+r)}}static setLogLevel(r){this._logLevel=r}}b(c,"_prefix","[Cypress-SignalR-Mock] - "),b(c,"_logLevel",3);var h=function(e,r){return h=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,n){t.__proto__=n}||function(t,n){for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(t[o]=n[o])},h(e,r)};function v(e,r){if(typeof r!="function"&&r!==null)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");h(e,r);function t(){this.constructor=e}e.prototype=r===null?Object.create(r):(t.prototype=r.prototype,new t)}function E(e){var r=typeof Symbol=="function"&&Symbol.iterator,t=r&&e[r],n=0;if(t)return t.call(e);if(e&&typeof e.length=="number")return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw new TypeError(r?"Object is not iterable.":"Symbol.iterator is not defined.")}function y(e,r){var t=typeof Symbol=="function"&&e[Symbol.iterator];if(!t)return e;var n=t.call(e),o,i=[],s;try{for(;(r===void 0||r-- >0)&&!(o=n.next()).done;)i.push(o.value)}catch(u){s={error:u}}finally{try{o&&!o.done&&(t=n.return)&&t.call(n)}finally{if(s)throw s.error}}return i}function _(e,r,t){if(t||arguments.length===2)for(var n=0,o=r.length,i;n0},enumerable:!1,configurable:!0}),r.prototype._trySubscribe=function(t){return this._throwIfClosed(),e.prototype._trySubscribe.call(this,t)},r.prototype._subscribe=function(t){return this._throwIfClosed(),this._checkFinalizedStatuses(t),this._innerSubscribe(t)},r.prototype._innerSubscribe=function(t){var n=this,o=this,i=o.hasError,s=o.isStopped,u=o.observers;return i||s?A:(this.currentObservers=null,u.push(t),new g(function(){n.currentObservers=null,P(u,t)}))},r.prototype._checkFinalizedStatuses=function(t){var n=this,o=n.hasError,i=n.thrownError,s=n.isStopped;o?t.error(i):s&&t.complete()},r.prototype.asObservable=function(){var t=new H;return t.source=this,t},r.create=function(t,n){return new Y(t,n)},r}(H),Y=function(e){v(r,e);function r(t,n){var o=e.call(this)||this;return o.destination=t,o.source=n,o}return r.prototype.next=function(t){var n,o;(o=(n=this.destination)===null||n===void 0?void 0:n.next)===null||o===void 0||o.call(n,t)},r.prototype.error=function(t){var n,o;(o=(n=this.destination)===null||n===void 0?void 0:n.error)===null||o===void 0||o.call(n,t)},r.prototype.complete=function(){var t,n;(n=(t=this.destination)===null||t===void 0?void 0:t.complete)===null||n===void 0||n.call(t)},r.prototype._subscribe=function(t){var n,o;return(o=(n=this.source)===null||n===void 0?void 0:n.subscribe(t))!==null&&o!==void 0?o:A},r}(O);class fr{constructor(r,t){this._subject=r,this._observer=t}dispose(){const r=this._subject.observers.indexOf(this._observer);r>-1&&this._subject.observers.splice(r,1),this._subject.observers.length===0&&this._subject.cancelCallback&&this._subject.cancelCallback().catch(t=>{})}}class hr{constructor(){this.observers=[]}next(r){for(const t of this.observers)t.next(r)}error(r){for(const t of this.observers)t.error&&t.error(r)}complete(){for(const r of this.observers)r.complete&&r.complete()}subscribe(r){return this.observers.push(r),new fr(this,r)}}class pr{constructor(r){b(this,"_hubConnectionData",[]);b(this,"_serverInvokes",[]);b(this,"name");this.name=r}publish(r,t){r=r.toLowerCase();const n=this._hubConnectionData.filter(o=>o.messageType===r);if(n.length===0){c.warn(`No subscribers for ${r}`);return}c.debug(`Publishing action: ${r} to ${n.length} subscribers`),n.forEach(o=>{o.channel.next({name:r,value:t})})}verify(r,t){r=r.toLowerCase();const n=this._serverInvokes.filter(o=>o.action===r);t&&t(n)}on(r,t){r=r.toLowerCase(),this._hubConnectionData.some(i=>i.messageType===r)||this._hubConnectionData.push({messageType:r,isStream:!1,channel:new O,subscriptions:[]});let n=this._hubConnectionData.find(i=>i.messageType===r);if(!n)throw new Error(`Could not find connection data for ${r}`);let o=n.channel.subscribe(i=>{t(i.value)});n.subscriptions.push({handler:t,subscription:o})}stream(r,...t){r=r.toLowerCase(),this._hubConnectionData.some(i=>i.messageType===r)||this._hubConnectionData.push({messageType:r,isStream:!0,channel:new O,subscriptions:[]});let n=this._hubConnectionData.find(i=>i.messageType===r);if(!n)throw new Error(`Could not find connection data for ${r}`);const o=new hr;return n.channel.subscribe({next:i=>o.next(i),error:i=>o.error(i),complete:()=>o.complete()}),o}invoke(r,...t){return new Promise(n=>{this._serverInvokes.push({action:r,args:t}),n(0)})}off(r,t){r=r.toLowerCase();const n=this._hubConnectionData.findIndex(o=>o.messageType===r);if(n==-1){c.warn(`No channels registered for action name: ${r}`);return}if(t){const o=this._hubConnectionData[n].subscriptions.findIndex(i=>i.handler===t);if(o==-1){c.warn(`Could not find the handler to delete for action name: ${r}`);return}this._hubConnectionData[n].subscriptions.splice(o,1),this._hubConnectionData[n].subscriptions.length===0&&this._hubConnectionData.splice(n,1)}else this._hubConnectionData.splice(n,1)}onclose(r){}start(){return Promise.resolve()}async stop(){return Promise.resolve()}onreconnecting(r){}onreconnected(r){}send(r,...t){return Promise.resolve()}}function B(){return T()?!1:window.hasOwnProperty("Cypress")}function m(){return!T()&&window["cypress-signalr-mock"]?window["cypress-signalr-mock"]:(q(),m())}function br(e){T()||(window["cypress-signalr-mock"]=e)}function q(){br(dr())}function dr(){return{mocks:[]}}function G(e){return m().mocks.find(t=>t.name===e)??null}function T(){return typeof window>"u"?(c.error("window is not defined. This most likely happens during SSR, which is not supported",!1),!0):!1}function J(){var e;return typeof process<"u"&&((e=process==null?void 0:process.env)==null?void 0:e.hasOwnProperty("VITEST"))&&process.env.VITEST==="true"}function vr(){if(!B()){c.debug("Cypress is not running, skipping setup of Cypress commands");return}const e=window.Cypress;e.Commands.add("hubPublish",K),e.Commands.add("hubVerifyInvokes",Q),e.Commands.add("hubClear",X),e.Commands.add("hubPrintData",W)}function K(e,r,t){const n=G(e);if(!n){c.error(`[cy.hubPublish] - HubConnectionMock not found for ${e}`);return}n.publish(r,t)}function Q(e,r,t){const n=G(e);if(!n){c.error(`[cy.hubVerify] - HubConnectionMock not found for hub with name: ${e}`);return}n.verify(r,t)}function W(){c.info('Current window["cypress-signalr-mock"] data:',m())}function X(){q()}vr(),Z("default");function Z(e,{debug:r,enableForVitest:t}={}){if(r&&c.setLogLevel(4),!t&&J()&&c.info(`Vitest is running but 'enableForVitest' is ${t}, skip enabling CypressSignalRMock...`),B()||t&&J()){const n=new pr(e);return m().mocks.push(n),n}return null}a.hubClear=X,a.hubPrintData=W,a.hubPublish=K,a.hubVerify=Q,a.useCypressSignalRMock=Z,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})}); //# sourceMappingURL=index.umd.cjs.map