import { SELECTOR_NOT_SPECIFIED , } from "../errors" ; export const getElement = ( queryOrElement ) : HTMLElement => { if ( typeof queryOrElement === "string" ) { return document . querySelector ( queryOrElement ) as HTMLElement ; } else if ( queryOrElement . nodeType > 0 ) { return queryOrElement ; } else { throw new Error ( SELECTOR_NOT_SPECIFIED ) ; } } ; export const setWrapperSize = ( element , wrapper ) => { const bbox = element . getBoundingClientRect ( ) ; wrapper . style . width = `${ bbox . width }px` ; wrapper . style . height = `${ bbox . height }px` ; } ; export const wrapElement = ( element , isLeaf = false ) : HTMLElement => { const wrapper = document . createElement ( "div" ) ; const elStyle = getComputedStyle ( element ) ; const isFirefox = navigator . userAgent . indexOf ( "Firefox" ) > 0 ; if ( elStyle . position === "absolute" || elStyle . position === "fixed" ) { wrapper . style . position = elStyle . position ; wrapper . style . top = elStyle . top ; wrapper . style . left = elStyle . left ; } else { wrapper . style . position = "relative" ; } if ( elStyle . display !== "inline" && elStyle . display !== "content" && elStyle . display !== "unset" ) { wrapper . style . display = elStyle . display ; } wrapper . style . backfaceVisibility = "hidden" ; wrapper . style . overflow = "visible" ; ( wrapper . style as any ) . willChange = "transform" ; wrapper . style . pointerEvents = elStyle . pointerEvents ; setWrapperSize ( element , wrapper ) ; element . parentElement ! . replaceChild ( wrapper , element ) ; wrapper . appendChild ( element ) ; if ( ! isLeaf ) { element . style . transformStyle = "preserve-3d" ; } element . style . overflow = "visible" ; if ( ! isFirefox ) { ( element . style as any ) . willChange = "transform" ; } element . style . position = "absolute" ; element . style . top = "0" ; element . style . left = "0" ; element . style . right = "0" ; return wrapper ; } ; export interface ArrayLike < T > { length : number ; [ index ] : T ; } export function toArray < T > ( iterable ) { return [ ] . slice . call ( iterable ) ; }