nonChromiumPlatformUtils-WEX4VIW3.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  1. import {
  2. rectToClientRect
  3. } from "./chunk-LPWNO2ZS.js";
  4. import "./chunk-2TTT3V5O.js";
  5. import "./chunk-IOZKU7B2.js";
  6. import "./chunk-S5KM4IGW.js";
  7. // node_modules/@esri/calcite-components/dist/components/nonChromiumPlatformUtils.js
  8. function getTrueOffsetParent(element) {
  9. if (!isHTMLElement(element) || getComputedStyle(element).position === "fixed") {
  10. return null;
  11. }
  12. return composedOffsetParent(element);
  13. }
  14. function composedOffsetParent(element) {
  15. let { offsetParent } = element;
  16. let ancestor = element;
  17. let foundInsideSlot = false;
  18. while (ancestor && ancestor !== offsetParent) {
  19. const { assignedSlot } = ancestor;
  20. if (assignedSlot) {
  21. let newOffsetParent = assignedSlot.offsetParent;
  22. if (getComputedStyle(assignedSlot).display === "contents") {
  23. const hadStyleAttribute = assignedSlot.hasAttribute("style");
  24. const oldDisplay = assignedSlot.style.display;
  25. assignedSlot.style.display = getComputedStyle(ancestor).display;
  26. newOffsetParent = assignedSlot.offsetParent;
  27. assignedSlot.style.display = oldDisplay;
  28. if (!hadStyleAttribute) {
  29. assignedSlot.removeAttribute("style");
  30. }
  31. }
  32. ancestor = assignedSlot;
  33. if (offsetParent !== newOffsetParent) {
  34. offsetParent = newOffsetParent;
  35. foundInsideSlot = true;
  36. }
  37. } else if (isShadowRoot(ancestor) && ancestor.host && foundInsideSlot) {
  38. break;
  39. }
  40. ancestor = isShadowRoot(ancestor) && ancestor.host || ancestor.parentNode;
  41. }
  42. return offsetParent;
  43. }
  44. function getElementRects(_ref) {
  45. const { reference, floating, strategy } = _ref;
  46. return {
  47. reference: getRectRelativeToOffsetParent(reference, getOffsetParent(floating), strategy),
  48. floating: { ...getDimensions(floating), x: 0, y: 0 }
  49. };
  50. }
  51. function isWindow(value) {
  52. return value && value.document && value.location && value.alert && value.setInterval;
  53. }
  54. function getWindow(node) {
  55. if (node == null) {
  56. return window;
  57. }
  58. if (!isWindow(node)) {
  59. const ownerDocument = node.ownerDocument;
  60. return ownerDocument ? ownerDocument.defaultView || window : window;
  61. }
  62. return node;
  63. }
  64. function getComputedStyle(element) {
  65. return getWindow(element).getComputedStyle(element);
  66. }
  67. function getNodeName(node) {
  68. return isWindow(node) ? "" : node ? (node.nodeName || "").toLowerCase() : "";
  69. }
  70. function getUAString() {
  71. const uaData = navigator.userAgentData;
  72. if (uaData != null && uaData.brands) {
  73. return uaData.brands.map((item) => item.brand + "/" + item.version).join(" ");
  74. }
  75. return navigator.userAgent;
  76. }
  77. function isHTMLElement(value) {
  78. return value instanceof getWindow(value).HTMLElement;
  79. }
  80. function isElement(value) {
  81. return value instanceof getWindow(value).Element;
  82. }
  83. function isNode(value) {
  84. return value instanceof getWindow(value).Node;
  85. }
  86. function isShadowRoot(node) {
  87. if (typeof ShadowRoot === "undefined") {
  88. return false;
  89. }
  90. const OwnElement = getWindow(node).ShadowRoot;
  91. return node instanceof OwnElement || node instanceof ShadowRoot;
  92. }
  93. function isOverflowElement(element) {
  94. const { overflow, overflowX, overflowY, display } = getComputedStyle(element);
  95. return /auto|scroll|overlay|hidden/.test(overflow + overflowY + overflowX) && !["inline", "contents"].includes(display);
  96. }
  97. function isTableElement(element) {
  98. return ["table", "td", "th"].includes(getNodeName(element));
  99. }
  100. function isContainingBlock(element) {
  101. const isFirefox = /firefox/i.test(getUAString());
  102. const css = getComputedStyle(element);
  103. return css.transform !== "none" || css.perspective !== "none" || isFirefox && css.willChange === "filter" || isFirefox && (css.filter ? css.filter !== "none" : false) || ["transform", "perspective"].some((value) => css.willChange.includes(value)) || ["paint", "layout", "strict", "content"].some(
  104. (value) => {
  105. const contain = css.contain;
  106. return contain != null ? contain.includes(value) : false;
  107. }
  108. );
  109. }
  110. function isLayoutViewport() {
  111. return !/^((?!chrome|android).)*safari/i.test(getUAString());
  112. }
  113. function isLastTraversableNode(node) {
  114. return ["html", "body", "#document"].includes(getNodeName(node));
  115. }
  116. var min = Math.min;
  117. var max = Math.max;
  118. var round = Math.round;
  119. function getBoundingClientRect(element, includeScale, isFixedStrategy) {
  120. var _win$visualViewport$o, _win$visualViewport, _win$visualViewport$o2, _win$visualViewport2;
  121. if (includeScale === void 0) {
  122. includeScale = false;
  123. }
  124. if (isFixedStrategy === void 0) {
  125. isFixedStrategy = false;
  126. }
  127. const clientRect = element.getBoundingClientRect();
  128. let scaleX = 1;
  129. let scaleY = 1;
  130. if (includeScale && isHTMLElement(element)) {
  131. scaleX = element.offsetWidth > 0 ? round(clientRect.width) / element.offsetWidth || 1 : 1;
  132. scaleY = element.offsetHeight > 0 ? round(clientRect.height) / element.offsetHeight || 1 : 1;
  133. }
  134. const win = isElement(element) ? getWindow(element) : window;
  135. const addVisualOffsets = !isLayoutViewport() && isFixedStrategy;
  136. const x = (clientRect.left + (addVisualOffsets ? (_win$visualViewport$o = (_win$visualViewport = win.visualViewport) == null ? void 0 : _win$visualViewport.offsetLeft) != null ? _win$visualViewport$o : 0 : 0)) / scaleX;
  137. const y = (clientRect.top + (addVisualOffsets ? (_win$visualViewport$o2 = (_win$visualViewport2 = win.visualViewport) == null ? void 0 : _win$visualViewport2.offsetTop) != null ? _win$visualViewport$o2 : 0 : 0)) / scaleY;
  138. const width = clientRect.width / scaleX;
  139. const height = clientRect.height / scaleY;
  140. return {
  141. width,
  142. height,
  143. top: y,
  144. right: x + width,
  145. bottom: y + height,
  146. left: x,
  147. x,
  148. y
  149. };
  150. }
  151. function getDocumentElement(node) {
  152. return ((isNode(node) ? node.ownerDocument : node.document) || window.document).documentElement;
  153. }
  154. function getNodeScroll(element) {
  155. if (isElement(element)) {
  156. return {
  157. scrollLeft: element.scrollLeft,
  158. scrollTop: element.scrollTop
  159. };
  160. }
  161. return {
  162. scrollLeft: element.pageXOffset,
  163. scrollTop: element.pageYOffset
  164. };
  165. }
  166. function getWindowScrollBarX(element) {
  167. return getBoundingClientRect(getDocumentElement(element)).left + getNodeScroll(element).scrollLeft;
  168. }
  169. function isScaled(element) {
  170. const rect = getBoundingClientRect(element);
  171. return round(rect.width) !== element.offsetWidth || round(rect.height) !== element.offsetHeight;
  172. }
  173. function getRectRelativeToOffsetParent(element, offsetParent, strategy) {
  174. const isOffsetParentAnElement = isHTMLElement(offsetParent);
  175. const documentElement = getDocumentElement(offsetParent);
  176. const rect = getBoundingClientRect(
  177. element,
  178. isOffsetParentAnElement && isScaled(offsetParent),
  179. strategy === "fixed"
  180. );
  181. let scroll = {
  182. scrollLeft: 0,
  183. scrollTop: 0
  184. };
  185. const offsets = {
  186. x: 0,
  187. y: 0
  188. };
  189. if (isOffsetParentAnElement || !isOffsetParentAnElement && strategy !== "fixed") {
  190. if (getNodeName(offsetParent) !== "body" || isOverflowElement(documentElement)) {
  191. scroll = getNodeScroll(offsetParent);
  192. }
  193. if (isHTMLElement(offsetParent)) {
  194. const offsetRect = getBoundingClientRect(offsetParent, true);
  195. offsets.x = offsetRect.x + offsetParent.clientLeft;
  196. offsets.y = offsetRect.y + offsetParent.clientTop;
  197. } else if (documentElement) {
  198. offsets.x = getWindowScrollBarX(documentElement);
  199. }
  200. }
  201. return {
  202. x: rect.left + scroll.scrollLeft - offsets.x,
  203. y: rect.top + scroll.scrollTop - offsets.y,
  204. width: rect.width,
  205. height: rect.height
  206. };
  207. }
  208. function getParentNode(node) {
  209. if (getNodeName(node) === "html") {
  210. return node;
  211. }
  212. return node.assignedSlot || node.parentNode || (isShadowRoot(node) ? node.host : null) || getDocumentElement(node);
  213. }
  214. function getContainingBlock(element) {
  215. let currentNode = getParentNode(element);
  216. if (isShadowRoot(currentNode)) {
  217. currentNode = currentNode.host;
  218. }
  219. while (isHTMLElement(currentNode) && !isLastTraversableNode(currentNode)) {
  220. if (isContainingBlock(currentNode)) {
  221. return currentNode;
  222. } else {
  223. const parent = currentNode.parentNode;
  224. currentNode = isShadowRoot(parent) ? parent.host : parent;
  225. }
  226. }
  227. return null;
  228. }
  229. function getOffsetParent(element) {
  230. const window2 = getWindow(element);
  231. let offsetParent = getTrueOffsetParent(element);
  232. while (offsetParent && isTableElement(offsetParent) && getComputedStyle(offsetParent).position === "static") {
  233. offsetParent = getTrueOffsetParent(offsetParent);
  234. }
  235. if (offsetParent && (getNodeName(offsetParent) === "html" || getNodeName(offsetParent) === "body" && getComputedStyle(offsetParent).position === "static" && !isContainingBlock(offsetParent))) {
  236. return window2;
  237. }
  238. return offsetParent || getContainingBlock(element) || window2;
  239. }
  240. function getDimensions(element) {
  241. if (isHTMLElement(element)) {
  242. return {
  243. width: element.offsetWidth,
  244. height: element.offsetHeight
  245. };
  246. }
  247. const rect = getBoundingClientRect(element);
  248. return {
  249. width: rect.width,
  250. height: rect.height
  251. };
  252. }
  253. function getViewportRect(element, strategy) {
  254. const win = getWindow(element);
  255. const html = getDocumentElement(element);
  256. const visualViewport = win.visualViewport;
  257. let width = html.clientWidth;
  258. let height = html.clientHeight;
  259. let x = 0;
  260. let y = 0;
  261. if (visualViewport) {
  262. width = visualViewport.width;
  263. height = visualViewport.height;
  264. const layoutViewport = isLayoutViewport();
  265. if (layoutViewport || !layoutViewport && strategy === "fixed") {
  266. x = visualViewport.offsetLeft;
  267. y = visualViewport.offsetTop;
  268. }
  269. }
  270. return {
  271. width,
  272. height,
  273. x,
  274. y
  275. };
  276. }
  277. function getDocumentRect(element) {
  278. var _element$ownerDocumen;
  279. const html = getDocumentElement(element);
  280. const scroll = getNodeScroll(element);
  281. const body = (_element$ownerDocumen = element.ownerDocument) == null ? void 0 : _element$ownerDocumen.body;
  282. const width = max(html.scrollWidth, html.clientWidth, body ? body.scrollWidth : 0, body ? body.clientWidth : 0);
  283. const height = max(html.scrollHeight, html.clientHeight, body ? body.scrollHeight : 0, body ? body.clientHeight : 0);
  284. let x = -scroll.scrollLeft + getWindowScrollBarX(element);
  285. const y = -scroll.scrollTop;
  286. if (getComputedStyle(body || html).direction === "rtl") {
  287. x += max(html.clientWidth, body ? body.clientWidth : 0) - width;
  288. }
  289. return {
  290. width,
  291. height,
  292. x,
  293. y
  294. };
  295. }
  296. function getNearestOverflowAncestor(node) {
  297. const parentNode = getParentNode(node);
  298. if (isLastTraversableNode(parentNode)) {
  299. return node.ownerDocument.body;
  300. }
  301. if (isHTMLElement(parentNode) && isOverflowElement(parentNode)) {
  302. return parentNode;
  303. }
  304. return getNearestOverflowAncestor(parentNode);
  305. }
  306. function getOverflowAncestors(node, list) {
  307. var _node$ownerDocument;
  308. if (list === void 0) {
  309. list = [];
  310. }
  311. const scrollableAncestor = getNearestOverflowAncestor(node);
  312. const isBody = scrollableAncestor === ((_node$ownerDocument = node.ownerDocument) == null ? void 0 : _node$ownerDocument.body);
  313. const win = getWindow(scrollableAncestor);
  314. const target = isBody ? [win].concat(win.visualViewport || [], isOverflowElement(scrollableAncestor) ? scrollableAncestor : []) : scrollableAncestor;
  315. const updatedList = list.concat(target);
  316. return isBody ? updatedList : updatedList.concat(getOverflowAncestors(target));
  317. }
  318. function contains(parent, child) {
  319. const rootNode = child.getRootNode == null ? void 0 : child.getRootNode();
  320. if (parent.contains(child)) {
  321. return true;
  322. } else if (rootNode && isShadowRoot(rootNode)) {
  323. let next = child;
  324. do {
  325. if (next && parent === next) {
  326. return true;
  327. }
  328. next = next.parentNode || next.host;
  329. } while (next);
  330. }
  331. return false;
  332. }
  333. function getNearestParentCapableOfEscapingClipping(element, clippingAncestors) {
  334. let currentNode = element;
  335. while (currentNode && !isLastTraversableNode(currentNode) && !clippingAncestors.includes(currentNode)) {
  336. if (isElement(currentNode) && ["absolute", "fixed"].includes(getComputedStyle(currentNode).position)) {
  337. break;
  338. }
  339. const parentNode = getParentNode(currentNode);
  340. currentNode = isShadowRoot(parentNode) ? parentNode.host : parentNode;
  341. }
  342. return currentNode;
  343. }
  344. function getInnerBoundingClientRect(element, strategy) {
  345. const clientRect = getBoundingClientRect(element, false, strategy === "fixed");
  346. const top = clientRect.top + element.clientTop;
  347. const left = clientRect.left + element.clientLeft;
  348. return {
  349. top,
  350. left,
  351. x: left,
  352. y: top,
  353. right: left + element.clientWidth,
  354. bottom: top + element.clientHeight,
  355. width: element.clientWidth,
  356. height: element.clientHeight
  357. };
  358. }
  359. function getClientRectFromClippingAncestor(element, clippingParent, strategy) {
  360. if (clippingParent === "viewport") {
  361. return rectToClientRect(getViewportRect(element, strategy));
  362. }
  363. if (isElement(clippingParent)) {
  364. return getInnerBoundingClientRect(clippingParent, strategy);
  365. }
  366. return rectToClientRect(getDocumentRect(getDocumentElement(element)));
  367. }
  368. function getClippingAncestors(element) {
  369. const clippingAncestors = getOverflowAncestors(element);
  370. const nearestEscapableParent = getNearestParentCapableOfEscapingClipping(element, clippingAncestors);
  371. let clipperElement = null;
  372. if (nearestEscapableParent && isHTMLElement(nearestEscapableParent)) {
  373. const offsetParent = getOffsetParent(nearestEscapableParent);
  374. if (isOverflowElement(nearestEscapableParent)) {
  375. clipperElement = nearestEscapableParent;
  376. } else if (isHTMLElement(offsetParent)) {
  377. clipperElement = offsetParent;
  378. }
  379. }
  380. if (!isElement(clipperElement)) {
  381. return [];
  382. }
  383. return clippingAncestors.filter((clippingAncestors2) => clipperElement && isElement(clippingAncestors2) && contains(clippingAncestors2, clipperElement) && getNodeName(clippingAncestors2) !== "body");
  384. }
  385. function getClippingRect(_ref) {
  386. let { element, boundary, rootBoundary, strategy } = _ref;
  387. const mainClippingAncestors = boundary === "clippingAncestors" ? getClippingAncestors(element) : [].concat(boundary);
  388. const clippingAncestors = [...mainClippingAncestors, rootBoundary];
  389. const firstClippingAncestor = clippingAncestors[0];
  390. const clippingRect = clippingAncestors.reduce((accRect, clippingAncestor) => {
  391. const rect = getClientRectFromClippingAncestor(element, clippingAncestor, strategy);
  392. accRect.top = max(rect.top, accRect.top);
  393. accRect.right = min(rect.right, accRect.right);
  394. accRect.bottom = min(rect.bottom, accRect.bottom);
  395. accRect.left = max(rect.left, accRect.left);
  396. return accRect;
  397. }, getClientRectFromClippingAncestor(element, firstClippingAncestor, strategy));
  398. return {
  399. width: clippingRect.right - clippingRect.left,
  400. height: clippingRect.bottom - clippingRect.top,
  401. x: clippingRect.left,
  402. y: clippingRect.top
  403. };
  404. }
  405. export {
  406. getClippingRect,
  407. getElementRects,
  408. getOffsetParent
  409. };
  410. /*!
  411. * All material copyright ESRI, All Rights Reserved, unless otherwise specified.
  412. * See https://github.com/Esri/calcite-components/blob/master/LICENSE.md for details.
  413. * v1.0.0-beta.97
  414. */
  415. //# sourceMappingURL=nonChromiumPlatformUtils-WEX4VIW3.js.map