UNPKG

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 3.21 kB
{"version":3,"file":"dom-B-SQyhbA.mjs","sources":["../src/utils/dom.ts"],"sourcesContent":["import type {Slot} from 'vue'\n\n/**\n * @deprecated only used in BFormGroup, which is not an SFC... Function could probably be replaced with pure Vue\n */\nexport const attemptFocus = (\n el: Readonly<HTMLElement>,\n options: Readonly<FocusOptions> = {}\n): boolean => {\n const getActiveElement = (excludes: readonly HTMLElement[] = []): Element | null => {\n const {activeElement} = document\n return activeElement && !excludes.some((el) => el === activeElement) ? activeElement : null\n }\n\n const isActiveElement = (el: Readonly<HTMLElement>): boolean => el === getActiveElement()\n\n try {\n el.focus(options)\n } catch (e) {\n // eslint-disable-next-line no-console\n console.error(e)\n }\n return isActiveElement(el)\n}\n\nexport const isEmptySlot = (el: Slot | undefined): boolean => (el?.() ?? []).length === 0\n\n/**\n * @deprecated only used in BFormGroup, which is not an SFC... Function could probably be replaced with pure Vue\n */\nexport const isVisible = (el: Readonly<Element>): boolean => {\n //if (!isElement(el) || !el.parentNode || !contains(DOCUMENT.body, el)) {\n // Note this can fail for shadow dom elements since they\n // are not a direct descendant of document.body\n //return false\n //}\n if (el.getAttribute('display') === 'none') {\n // We do this check to help with vue-test-utils when using v-show\n return false\n }\n // All browsers support getBoundingClientRect(), except JSDOM as it returns all 0's for values :(\n // So any tests that need isVisible will fail in JSDOM\n // Except when we override the getBCR prototype in some tests\n const bcr = el.getBoundingClientRect()\n return !!(bcr && bcr.height > 0 && bcr.width > 0)\n}\n\nexport const getTransitionDelay = (element: Readonly<HTMLElement>) => {\n const style = window.getComputedStyle(element)\n // if multiple durations are defined, we take the first\n const transitionDelay = style.transitionDelay.split(',')[0] || ''\n const transitionDuration = style.transitionDuration.split(',')[0] || ''\n const transitionDelayMs = Number(transitionDelay.slice(0, -1)) * 1000\n const transitionDurationMs = Number(transitionDuration.slice(0, -1)) * 1000\n return transitionDelayMs + transitionDurationMs\n}\n"],"names":["el"],"mappings":"AAKO,MAAM,eAAe,CAC1B,IACA,UAAkC,OACtB;AACZ,QAAM,mBAAmB,CAAC,WAAmC,OAAuB;AAC5E,UAAA,EAAC,cAAiB,IAAA;AACjB,WAAA,iBAAiB,CAAC,SAAS,KAAK,CAACA,QAAOA,QAAO,aAAa,IAAI,gBAAgB;AAAA,EAAA;AAGzF,QAAM,kBAAkB,CAACA,QAAuCA,QAAO,iBAAiB;AAEpF,MAAA;AACF,OAAG,MAAM,OAAO;AAAA,WACT,GAAG;AAEV,YAAQ,MAAM,CAAC;AAAA,EACjB;AACA,SAAO,gBAAgB,EAAE;AAC3B;AAEO,MAAM,cAAc,CAAC,SAAmC,+BAAU,CAAA,GAAI,WAAW;AAK3E,MAAA,YAAY,CAAC,OAAmC;AAM3D,MAAI,GAAG,aAAa,SAAS,MAAM,QAAQ;AAElC,WAAA;AAAA,EACT;AAIM,QAAA,MAAM,GAAG;AACf,SAAO,CAAC,EAAE,OAAO,IAAI,SAAS,KAAK,IAAI,QAAQ;AACjD;AAEa,MAAA,qBAAqB,CAAC,YAAmC;AAC9D,QAAA,QAAQ,OAAO,iBAAiB,OAAO;AAE7C,QAAM,kBAAkB,MAAM,gBAAgB,MAAM,GAAG,EAAE,CAAC,KAAK;AAC/D,QAAM,qBAAqB,MAAM,mBAAmB,MAAM,GAAG,EAAE,CAAC,KAAK;AACrE,QAAM,oBAAoB,OAAO,gBAAgB,MAAM,GAAG,EAAE,CAAC,IAAI;AACjE,QAAM,uBAAuB,OAAO,mBAAmB,MAAM,GAAG,EAAE,CAAC,IAAI;AACvE,SAAO,oBAAoB;AAC7B;"}