{ "version": 3, "sources": [ "domUtils.ts" ], "names": [ "browser", "domObjects", "is", "win", "nodeContains", "parent", "child", "contains", "parentNode", "closest", "element", "selector", "matchesSelector", "node", "docFrag", "host", "window", "realWindow", "replace", "prefixedMatchesSelector", "getParent", "el", "indexOfDeepestElement", "elements", "deepestNodeIndex", "deepestNodeParents", "i", "length", "currentNode", "deepestNode", "currentNodeParent", "deepestNodeParent", "ownerDocument", "higherNode", "lowerNode", "parseInt", "getWindow", "getComputedStyle", "zIndex", "ancestryStart", "getNodeParents", "HTMLElement", "SVGElement", "SVGSVGElement", "ownerSVGElement", "currentNodeParents", "commonIndex", "parents", "lastChild", "previousSibling", "limit", "parentParent", "unshift", "matchesUpTo", "getActualElement", "correspondingUseElement", "getScrollXY", "relevantWindow", "x", "scrollX", "document", "documentElement", "scrollLeft", "y", "scrollY", "scrollTop", "getElementClientRect", "clientRect", "getBoundingClientRect", "getClientRects", "left", "right", "top", "bottom", "width", "height", "getElementRect", "isIOS7", "scroll", "getPath", "path", "push", "trySelector", "value", "string", "querySelector" ], "mappings": "OAEOA,MAAa,2BACbC,MAAgB,8BAChBC,MAAQ,yBACHC,MAAS,0BAEd,SAASC,aAAcC,EAAcC,GAC1C,GAAID,EAAOE,SACT,OAAOF,EAAOE,SAASD,GAGzB,KAAOA,GAAO,CACZ,GAAIA,IAAUD,EACZ,OAAO,EAGTC,EAASA,EAAeE,WAG1B,OAAO,SAGF,SAASC,QAASC,EAAeC,GACtC,KAAOT,EAAGQ,QAAQA,IAAU,CAC1B,GAAIE,gBAAgBF,EAASC,GAAa,OAAOD,EAEjDA,EAAUF,WAAWE,GAGvB,OAAO,YAGF,SAASF,WAAYK,GAC1B,IAAIR,EAASQ,EAAKL,WAElB,GAAIN,EAAGY,QAAQT,GAAS,CAGtB,MAAQA,EAAUA,EAAeU,OAASb,EAAGY,QAAQT,KAIrD,OAAOA,EAGT,OAAOA,SAGF,SAASO,gBAAiBF,EAAkBC,GAMjD,OAJIR,EAAIa,SAA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EAAIiC,UAAU1B,IAEzCyD,EAAWG,MAAUQ,EAAOpB,EAC5BS,EAAWI,OAAUO,EAAOpB,EAC5BS,EAAWK,KAAUM,EAAOf,EAC5BI,EAAWM,QAAUK,EAAOf,EAG9B,OAAOI,SAGF,SAASY,QAASlE,GACvB,MAAMmE,EAAO,GAEb,KAAOnE,GACLmE,EAAKC,KAAKpE,GACVA,EAAOL,WAAWK,GAGpB,OAAOmE,SAGF,SAASE,YAAaC,GAC3B,QAAKjF,EAAGkF,OAAOD,KAGflF,EAAW2D,SAASyB,cAAcF,IAC3B", "sourcesContent": [ "import { Rect, Target, Element } from '@interactjs/types/index'\n\nimport browser from './browser'\nimport domObjects from './domObjects'\nimport is from './is'\nimport * as win from './window'\n\nexport function nodeContains (parent: Node, child: Node) {\n if (parent.contains) {\n return parent.contains(child as Node)\n }\n\n while (child) {\n if (child === parent) {\n return true\n }\n\n child = (child as Node).parentNode\n }\n\n return false\n}\n\nexport function closest (element: Node, selector: string) {\n while (is.element(element)) {\n if (matchesSelector(element, selector)) { return element }\n\n element = parentNode(element)\n }\n\n return null\n}\n\nexport function parentNode (node: Node | Document) {\n let parent = node.parentNode\n\n if (is.docFrag(parent)) {\n // skip past #shado-root fragments\n // tslint:disable-next-line\n while ((parent = (parent as any).host) && is.docFrag(parent)) {\n continue\n }\n\n return parent\n }\n\n return parent\n}\n\nexport function matchesSelector (element: Element, selector: string) {\n // remove /deep/ from selectors if shadowDOM polyfill is used\n if (win.window !== win.realWindow) {\n selector = selector.replace(/\\/deep\\//g, ' ')\n }\n\n return element[browser.prefixedMatchesSelector](selector)\n}\n\nconst getParent = (el: Node | Document | ShadowRoot) => el.parentNode || (el as ShadowRoot).host\n\n// Test for the element that's \"above\" all other qualifiers\nexport function indexOfDeepestElement (elements: Element[] | NodeListOf) {\n let deepestNodeParents: Node[] = []\n let deepestNodeIndex: number\n\n for (let i = 0; i < elements.length; i++) {\n const currentNode = elements[i]\n const deepestNode: Node = elements[deepestNodeIndex]\n\n // node may appear in elements array multiple times\n if (!currentNode || i === deepestNodeIndex) {\n continue\n }\n\n if (!deepestNode) {\n deepestNodeIndex = i\n continue\n }\n\n const currentNodeParent = getParent(currentNode)\n const deepestNodeParent = getParent(deepestNode)\n\n // check if the deepest or current are document.documentElement/rootElement\n // - if the current node is, do nothing and continue\n if (currentNodeParent === currentNode.ownerDocument) {\n continue\n }\n // - if deepest is, update with the current node and continue to next\n else if (deepestNodeParent === currentNode.ownerDocument) {\n deepestNodeIndex = i\n continue\n }\n\n // compare zIndex of siblings\n if (currentNodeParent === deepestNodeParent) {\n if (zIndexIsHigherThan(currentNode, deepestNode)) {\n deepestNodeIndex = i\n }\n\n continue\n }\n\n // populate the ancestry array for the latest deepest node\n deepestNodeParents = deepestNodeParents.length ? deepestNodeParents : getNodeParents(deepestNode)\n\n let ancestryStart: Node\n\n // if the deepest node is an HTMLElement and the current node is a non root svg element\n if (deepestNode instanceof domObjects.HTMLElement &&\n currentNode instanceof domObjects.SVGElement &&\n !(currentNode instanceof domObjects.SVGSVGElement)\n ) {\n // TODO: is this check necessary? Was this for HTML elements embedded in SVG?\n if (currentNode === deepestNodeParent) {\n continue\n }\n\n ancestryStart = currentNode.ownerSVGElement\n }\n else {\n ancestryStart = currentNode\n }\n\n const currentNodeParents = getNodeParents(ancestryStart, deepestNode.ownerDocument)\n let commonIndex = 0\n\n // get (position of closest common ancestor) + 1\n while (currentNodeParents[commonIndex] && currentNodeParents[commonIndex] === deepestNodeParents[commonIndex]) {\n commonIndex++\n }\n\n const parents = [\n currentNodeParents[commonIndex - 1],\n currentNodeParents[commonIndex],\n deepestNodeParents[commonIndex],\n ]\n\n let child = parents[0].lastChild\n\n while (child) {\n if (child === parents[1]) {\n deepestNodeIndex = i\n deepestNodeParents = currentNodeParents\n\n break\n }\n else if (child === parents[2]) {\n break\n }\n\n child = child.previousSibling\n }\n }\n\n return deepestNodeIndex\n}\n\nfunction getNodeParents (node: Node, limit?: Node) {\n const parents: Node[] = []\n let parent: Node = node\n let parentParent: Node\n\n while ((parentParent = getParent(parent)) && parent !== limit && parentParent !== parent.ownerDocument) {\n parents.unshift(parent)\n parent = parentParent\n }\n\n return parents\n}\n\nfunction zIndexIsHigherThan (higherNode: Node, lowerNode: Node) {\n const higherIndex = parseInt(win.getWindow(higherNode).getComputedStyle(higherNode).zIndex, 10) || 0\n const lowerIndex = parseInt(win.getWindow(lowerNode).getComputedStyle(lowerNode).zIndex, 10) || 0\n\n return higherIndex >= lowerIndex\n}\n\nexport function matchesUpTo (element: Element, selector: string, limit: Node) {\n while (is.element(element)) {\n if (matchesSelector(element, selector)) {\n return true\n }\n\n element = parentNode(element) as Element\n\n if (element === limit) {\n return matchesSelector(element, selector)\n }\n }\n\n return false\n}\n\nexport function getActualElement (element: Element) {\n return (element as SVGElement).correspondingUseElement || element\n}\n\nexport function getScrollXY (relevantWindow?: Window) {\n relevantWindow = relevantWindow || win.window\n return {\n x: relevantWindow.scrollX || relevantWindow.document.documentElement.scrollLeft,\n y: relevantWindow.scrollY || relevantWindow.document.documentElement.scrollTop,\n }\n}\n\nexport function getElementClientRect (element: Element): Required {\n const clientRect = (element instanceof domObjects.SVGElement\n ? element.getBoundingClientRect()\n : element.getClientRects()[0])\n\n return clientRect && {\n left : clientRect.left,\n right : clientRect.right,\n top : clientRect.top,\n bottom: clientRect.bottom,\n width : clientRect.width || clientRect.right - clientRect.left,\n height: clientRect.height || clientRect.bottom - clientRect.top,\n }\n}\n\nexport function getElementRect (element: Element) {\n const clientRect = getElementClientRect(element)\n\n if (!browser.isIOS7 && clientRect) {\n const scroll = getScrollXY(win.getWindow(element))\n\n clientRect.left += scroll.x\n clientRect.right += scroll.x\n clientRect.top += scroll.y\n clientRect.bottom += scroll.y\n }\n\n return clientRect\n}\n\nexport function getPath (node: Node | Document) {\n const path = []\n\n while (node) {\n path.push(node)\n node = parentNode(node)\n }\n\n return path\n}\n\nexport function trySelector (value: Target) {\n if (!is.string(value)) { return false }\n\n // an exception will be raised if it is invalid\n domObjects.document.querySelector(value)\n return true\n}\n" ] }