UNPKG

bootstrap-vue-next

Version:

Seamless integration of Vue 3, Bootstrap 5, and TypeScript for modern, type-safe UI development

1 lines 4.55 kB
{"version":3,"file":"dom-AhkaSoh8.mjs","names":[],"sources":["../src/utils/dom.ts"],"sourcesContent":["import type {Slot} from 'vue'\n\nexport const getSafeDocument = () => (typeof document !== 'undefined' ? document : null)\nexport const getSafeWindow = () => (typeof window !== 'undefined' ? window : null)\n\n// Get the currently active HTML element\nexport const getActiveElement = (excludes: readonly HTMLElement[] = []): Element | null => {\n const doc = getSafeDocument()\n if (doc === null) return null\n const {activeElement} = doc\n return activeElement && !excludes?.some((el) => el === activeElement) ? activeElement : null\n}\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 isActiveElement = (el: Readonly<HTMLElement>): boolean => el === getActiveElement()\n\n try {\n el.focus(options)\n } catch (e) {\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 = getSafeWindow()?.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\nexport const sortSlotElementsByPosition = (\n a: Readonly<HTMLElement> | null,\n b: Readonly<HTMLElement> | null\n): number => {\n if (typeof Node === 'undefined' || !Node || !a || !b) return 0\n const position = a.compareDocumentPosition(b)\n if (position & Node.DOCUMENT_POSITION_FOLLOWING) return -1\n if (position & Node.DOCUMENT_POSITION_PRECEDING) return 1\n return 0\n}\n\nconst defaultZModelIndex = 1055\nexport const getModalZIndex = (element?: Readonly<HTMLElement | null>): number => {\n const win = getSafeWindow()\n const doc = getSafeDocument()\n if (win === null || doc === null) return defaultZModelIndex\n const target = element ?? doc.body\n const raw = win.getComputedStyle(target).getPropertyValue('--bs-modal-zindex').trim()\n const parsed = Number.parseInt(raw, 10)\n return Number.isFinite(parsed) ? parsed : defaultZModelIndex\n}\n"],"mappings":";AAEA,IAAa,wBAAyB,OAAO,aAAa,cAAc,WAAW;AACnF,IAAa,sBAAuB,OAAO,WAAW,cAAc,SAAS;AAG7E,IAAa,oBAAoB,WAAmC,EAAE,KAAqB;CACzF,MAAM,MAAM,iBAAiB;AAC7B,KAAI,QAAQ,KAAM,QAAO;CACzB,MAAM,EAAC,kBAAiB;AACxB,QAAO,iBAAiB,CAAC,UAAU,MAAM,OAAO,OAAO,cAAc,GAAG,gBAAgB;;;;;AAM1F,IAAa,gBACX,IACA,UAAkC,EAAE,KACxB;CACZ,MAAM,mBAAmB,OAAuC,OAAO,kBAAkB;AAEzF,KAAI;AACF,KAAG,MAAM,QAAQ;UACV,GAAG;AACV,UAAQ,MAAM,EAAE;;AAElB,QAAO,gBAAgB,GAAG;;AAG5B,IAAa,eAAe,QAAmC,MAAM,IAAI,EAAE,EAAE,WAAW;;;;AAKxF,IAAa,aAAa,OAAmC;AAM3D,KAAI,GAAG,aAAa,UAAU,KAA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