import{c as t,V as e,I as s}from"./p-6e1ab235.js";import{c as i}from"./p-6a334573.js";import{C as o}from"./p-2d0d575f.js";import{d as n,D as r}from"./p-11e2dcf5.js";import{j as a,i as c}from"./p-f1c672e4.js";import{t as f}from"./p-b75ee3ba.js";var v=function(t,e,s,i){var o,n=arguments.length,r=n<3?e:null===i?i=Object.getOwnPropertyDescriptor(e,s):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(t,e,s,i);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(r=(n<3?o(r):n>3?o(e,s,r):o(e,s))||r);return n>3&&r&&Object.defineProperty(e,s,r),r};class h extends e{constructor(){super(...arguments),this.canHandle=({namespace:t})=>"vega"===t||!this.nativeEvent||"function"!=typeof this.nativeEvent.emit,this.handle=t=>this.vegaEvent.emit(t)}}v([t()],h.prototype,"vegaEvent",void 0),v([t()],h.prototype,"nativeEvent",void 0);class l extends e{constructor(){super(...arguments),this.canHandle=({namespace:t})=>"native"===t,this.handle=(t,e)=>(e&&e.stopPropagation(),this.nativeEvent.emit(t))}}!function(t,e,s,i){var o,n=arguments.length,r=n<3?e:null===i?i=Object.getOwnPropertyDescriptor(e,s):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(t,e,s,i);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(r=(n<3?o(r):n>3?o(e,s,r):o(e,s))||r);n>3&&r&&Object.defineProperty(e,s,r)}([t()],l.prototype,"nativeEvent",void 0);class p extends e{constructor(){super(...arguments),this.canHandle=({namespace:t,jqueryDelegatedEvent:e})=>"native"===t&&!!e&&a.isSupportDelegated(this.host,this.eventID),this.handle=(t,e)=>{const s=a.getStrategy(this.host,this.eventID);if(s)return e&&e.stopPropagation(),s.handle(this.host,t)}}setEventID(t){this.eventID=t}}!function(t,e,s,i){var o,n=arguments.length,r=n<3?e:null===i?i=Object.getOwnPropertyDescriptor(e,s):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(t,e,s,i);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(r=(n<3?o(r):n>3?o(e,s,r):o(e,s))||r);n>3&&r&&Object.defineProperty(e,s,r)}([t()],p.prototype,"host",void 0);var m=function(t,e,s,i){var o,n=arguments.length,r=n<3?e:null===i?i=Object.getOwnPropertyDescriptor(e,s):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(t,e,s,i);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(r=(n<3?o(r):n>3?o(e,s,r):o(e,s))||r);return n>3&&r&&Object.defineProperty(e,s,r),r};class u extends e{constructor({eventID:t}){super(),this.vegaEventEmitHandler=new h,this.nativeEventEmitHandler=new l,this.jqueryDelegatedEventEmitHandler=new p,this.emit=(t,e)=>{let s=!1;o.notify(n.getSubject(this.host,this.eventID),{host:this.host,detail:t,eventName:this.eventName,preventDefault:()=>{s=!0}});const i=c.getSemantics(this.host);let r;for(const s of this.eventHandlers)if(s.canHandle(i)){r=s.handle(t,e);break}return r&&s&&r.preventDefault(),r},this.removeObserverFromHost=()=>{Promise.resolve(!0).then((()=>{this.isNodeRemovedFromDocument(this.host)&&r.removeUniqueObserverFromNode(this.host,this.eventID)}))},this.eventID=t,this.eventName=t.getVegaName(),this.initialEventHandlers()}isNodeRemovedFromDocument(t){var e;return!(!t||(null===(e=f())||void 0===e?void 0:e.body.contains(t))||t.parentNode)}initialEventHandlers(){this.jqueryDelegatedEventEmitHandler.setEventID(this.eventID),this.eventHandlers=[this.vegaEventEmitHandler,this.jqueryDelegatedEventEmitHandler,this.nativeEventEmitHandler]}}function d(t,e,s){const o=e.getVegaName(),n=s||e.getNativeName();return i(t,u,[{mapFrom:"host",mapTo:"host"},{mapFrom:o,mapTo:"vegaEvent"},{mapFrom:n,mapTo:"nativeEvent",isOptional:!0}],[{mapFrom:"disconnectedCallback",mapTo:"removeObserverFromHost"}],[{eventID:e}])}m([s()],u.prototype,"vegaEventEmitHandler",void 0),m([s()],u.prototype,"nativeEventEmitHandler",void 0),m([s()],u.prototype,"jqueryDelegatedEventEmitHandler",void 0);export{d as c}