import { isPageNode } from '../' ; /**
 * Return top level parent for node before PageNode.
 * For example:
 * ```js
 * // for structure below
 * // Page / Frame / Group1 / Group2 / Text
 *
 * getTopLevelParent(Text) // Frame
 * ```
 */ export const getTopLevelParent = ( node ) : BaseNode => { if ( node && node . parent && ! isPageNode ( node . parent ) ) { return getTopLevelParent ( node . parent ) ; } else { return node ; } } ; /**
 * Calculate relative position of node based on provided parent or top level parent.
 * For example:
 * ```js
 * // for structure below
 * // Page / Frame / Group1 / Group2 / Text
 *
 * getRelativePosition(Text, Group1) // will calculate { x, y } based on Group1
 *
 * getRelativePosition(Text) // will calculate { x, y } based on Frame
 * ```
 **/ export const getRelativePosition = ( node , relativeNode ? ) => { relativeNode = relativeNode || ( getTopLevelParent ( node ) as BaseNode & LayoutMixin ) ; return { x : Math . abs ( Math . round ( relativeNode . absoluteTransform [ 0 ] [ 2 ] - node . absoluteTransform [ 0 ] [ 2 ] ) ) , y : Math . abs ( Math . round ( relativeNode . absoluteTransform [ 1 ] [ 2 ] - node . absoluteTransform [ 1 ] [ 2 ] ) ) } ; } ;