bootstrap-vue-next
Version:
BootstrapVueNext is an early and lovely component library for Vue 3 & Nuxt 3 based on Bootstrap 5 and Typescript.
1 lines • 4.23 kB
Source Map (JSON)
{"version":3,"file":"event-a_bi5ysw.mjs","sources":["../src/utils/event.ts"],"sourcesContent":["/**\n * @deprecated remove with parseEventOptions\n */\nexport const IS_BROWSER =\n typeof window !== 'undefined' &&\n typeof document !== 'undefined' &&\n typeof navigator !== 'undefined'\n\n// Normalize event options based on support of passive option\n// Exported only for testing purposes\n/**\n * @deprecated\n */\nexport const parseEventOptions = (\n options: boolean | Readonly<EventListenerOptions> | undefined\n): boolean | EventListenerOptions | undefined => {\n const HAS_PASSIVE_EVENT_SUPPORT = (() => {\n let passiveEventSupported = false\n if (IS_BROWSER) {\n try {\n const options = {\n // This function will be called when the browser\n // attempts to access the passive property\n get passive() {\n passiveEventSupported = true\n // eslint-disable-next-line no-useless-return\n return\n },\n }\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n WINDOW.addEventListener('test', options, options)\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n WINDOW.removeEventListener('test', options, options)\n } catch {\n passiveEventSupported = false\n }\n }\n return passiveEventSupported\n })()\n\n if (HAS_PASSIVE_EVENT_SUPPORT) {\n return typeof options === 'object' ? options : {capture: !!options || false}\n }\n // Need to translate to actual Boolean value\n return typeof options === 'object' ? options.capture : options\n}\n\n// Attach an event listener to an element\n/**\n * @deprecated\n */\nexport const eventOn = (\n el: Readonly<Element>,\n eventName: string,\n handler: EventListener,\n options: boolean | Readonly<EventListenerOptions> | undefined\n) => {\n if (el && el.addEventListener) {\n el.addEventListener(eventName, handler, parseEventOptions(options))\n }\n}\n\n// Remove an event listener from an element\n/**\n * @deprecated\n */\nexport const eventOff = (\n el: Readonly<Element>,\n eventName: string,\n handler: EventListener,\n options: boolean | Readonly<EventListenerOptions> | undefined\n) => {\n if (el && el.removeEventListener) {\n el.removeEventListener(eventName, handler, options)\n }\n}\n\n// Utility method to add/remove a event listener based on first argument (boolean)\n// It passes all other arguments to the `eventOn()` or `eventOff` method\n/**\n * @deprecated\n */\nexport const eventOnOff = (on: boolean, eventParams: Parameters<typeof eventOff>) => {\n const method = on ? eventOn : eventOff\n method(...eventParams)\n}\n\n// Utility method to prevent the default event handling and propagation\nexport const stopEvent = (\n event: Readonly<Event>,\n {preventDefault = true, propagation = false, immediatePropagation = false} = {}\n) => {\n if (preventDefault) {\n event.preventDefault()\n }\n if (propagation) {\n event.stopPropagation()\n }\n if (immediatePropagation) {\n event.stopImmediatePropagation()\n }\n}\n"],"names":["options"],"mappings":"AAGa,MAAA,aACX,OAAO,WAAW,eAClB,OAAO,aAAa,eACpB,OAAO,cAAc;AAOV,MAAA,oBAAoB,CAC/B,YAC+C;AAC/C,QAAM,6BAA6B,MAAM;AACvC,QAAI,wBAAwB;AAC5B,QAAI,YAAY;AACV,UAAA;AACF,cAAMA,WAAU;AAAA;AAAA;AAAA,UAGd,IAAI,UAAU;AACY,oCAAA;AAExB;AAAA,UAAA;AAAA,QAEJ;AAGO,eAAA,iBAAiB,QAAQA,UAASA,QAAO;AAGzC,eAAA,oBAAoB,QAAQA,UAASA,QAAO;AAAA,MAAA,QAC7C;AACkB,gCAAA;AAAA,MAAA;AAAA,IAC1B;AAEK,WAAA;AAAA,EAAA,GACN;AAEH,MAAI,2BAA2B;AACtB,WAAA,OAAO,YAAY,WAAW,UAAU,EAAC,SAAS,CAAC,CAAC,WAAW,MAAK;AAAA,EAAA;AAG7E,SAAO,OAAO,YAAY,WAAW,QAAQ,UAAU;AACzD;AAMO,MAAM,UAAU,CACrB,IACA,WACA,SACA,YACG;AACC,MAAA,MAAM,GAAG,kBAAkB;AAC7B,OAAG,iBAAiB,WAAW,SAAS,kBAAkB,OAAO,CAAC;AAAA,EAAA;AAEtE;AAMO,MAAM,WAAW,CACtB,IACA,WACA,SACA,YACG;AACC,MAAA,MAAM,GAAG,qBAAqB;AAC7B,OAAA,oBAAoB,WAA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