@aglyn/shared-util-dom 1.0.0-beta.143

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +7 -0
  3. package/package.json +37 -0
  4. package/src/constants/enums.d.ts +18 -0
  5. package/src/constants/enums.js +19 -0
  6. package/src/constants/enums.js.map +1 -0
  7. package/src/dom.d.ts +100 -0
  8. package/src/dom.js +51 -0
  9. package/src/dom.js.map +1 -0
  10. package/src/index.d.ts +17 -0
  11. package/src/index.js +18 -0
  12. package/src/index.js.map +1 -0
  13. package/src/lib/controllers/page-title.d.ts +47 -0
  14. package/src/lib/controllers/page-title.js +114 -0
  15. package/src/lib/controllers/page-title.js.map +1 -0
  16. package/src/lib/get-element-client-rect-bounding-inner.d.ts +19 -0
  17. package/src/lib/get-element-client-rect-bounding-inner.js +31 -0
  18. package/src/lib/get-element-client-rect-bounding-inner.js.map +1 -0
  19. package/src/lib/get-element-client-rect-bounding.d.ts +39 -0
  20. package/src/lib/get-element-client-rect-bounding.js +45 -0
  21. package/src/lib/get-element-client-rect-bounding.js.map +1 -0
  22. package/src/lib/get-element-clipping-rect.d.ts +26 -0
  23. package/src/lib/get-element-clipping-rect.js +77 -0
  24. package/src/lib/get-element-clipping-rect.js.map +1 -0
  25. package/src/lib/get-element-computed-style.d.ts +18 -0
  26. package/src/lib/get-element-computed-style.js +22 -0
  27. package/src/lib/get-element-computed-style.js.map +1 -0
  28. package/src/lib/get-element-document-element-rect.d.ts +19 -0
  29. package/src/lib/get-element-document-element-rect.js +43 -0
  30. package/src/lib/get-element-document-element-rect.js.map +1 -0
  31. package/src/lib/get-element-document-element.d.ts +18 -0
  32. package/src/lib/get-element-document-element.js +23 -0
  33. package/src/lib/get-element-document-element.js.map +1 -0
  34. package/src/lib/get-element-fragment-rects.d.ts +93 -0
  35. package/src/lib/get-element-fragment-rects.js +113 -0
  36. package/src/lib/get-element-fragment-rects.js.map +1 -0
  37. package/src/lib/get-element-list-scroll-parents.d.ts +19 -0
  38. package/src/lib/get-element-list-scroll-parents.js +38 -0
  39. package/src/lib/get-element-list-scroll-parents.js.map +1 -0
  40. package/src/lib/get-element-node-name.d.ts +18 -0
  41. package/src/lib/get-element-node-name.js +21 -0
  42. package/src/lib/get-element-node-name.js.map +1 -0
  43. package/src/lib/get-element-offset-parent.d.ts +18 -0
  44. package/src/lib/get-element-offset-parent.js +81 -0
  45. package/src/lib/get-element-offset-parent.js.map +1 -0
  46. package/src/lib/get-element-parent-node.d.ts +18 -0
  47. package/src/lib/get-element-parent-node.js +31 -0
  48. package/src/lib/get-element-parent-node.js.map +1 -0
  49. package/src/lib/get-element-rect-as-client-rect.d.ts +19 -0
  50. package/src/lib/get-element-rect-as-client-rect.js +27 -0
  51. package/src/lib/get-element-rect-as-client-rect.js.map +1 -0
  52. package/src/lib/get-element-scroll-parent.d.ts +18 -0
  53. package/src/lib/get-element-scroll-parent.js +36 -0
  54. package/src/lib/get-element-scroll-parent.js.map +1 -0
  55. package/src/lib/get-element-viewport-rect.d.ts +23 -0
  56. package/src/lib/get-element-viewport-rect.js +57 -0
  57. package/src/lib/get-element-viewport-rect.js.map +1 -0
  58. package/src/lib/get-element-window-scroll-bar-x.d.ts +18 -0
  59. package/src/lib/get-element-window-scroll-bar-x.js +31 -0
  60. package/src/lib/get-element-window-scroll-bar-x.js.map +1 -0
  61. package/src/lib/get-event-coordinates.d.ts +22 -0
  62. package/src/lib/get-event-coordinates.js +49 -0
  63. package/src/lib/get-event-coordinates.js.map +1 -0
  64. package/src/lib/get-iframe-document.d.ts +18 -0
  65. package/src/lib/get-iframe-document.js +29 -0
  66. package/src/lib/get-iframe-document.js.map +1 -0
  67. package/src/lib/get-node-window-scroll.d.ts +21 -0
  68. package/src/lib/get-node-window-scroll.js +28 -0
  69. package/src/lib/get-node-window-scroll.js.map +1 -0
  70. package/src/lib/get-node-window.d.ts +18 -0
  71. package/src/lib/get-node-window.js +34 -0
  72. package/src/lib/get-node-window.js.map +1 -0
  73. package/src/lib/get-owner-document.d.ts +2 -0
  74. package/src/lib/get-owner-document.js +40 -0
  75. package/src/lib/get-owner-document.js.map +1 -0
  76. package/src/lib/guards/element-contains-child-element.d.ts +18 -0
  77. package/src/lib/guards/element-contains-child-element.js +37 -0
  78. package/src/lib/guards/element-contains-child-element.js.map +1 -0
  79. package/src/lib/guards/event-has-viewport-coordinates.d.ts +18 -0
  80. package/src/lib/guards/event-has-viewport-coordinates.js +21 -0
  81. package/src/lib/guards/event-has-viewport-coordinates.js.map +1 -0
  82. package/src/lib/guards/is-element-html-element.d.ts +18 -0
  83. package/src/lib/guards/is-element-html-element.js +26 -0
  84. package/src/lib/guards/is-element-html-element.js.map +1 -0
  85. package/src/lib/guards/is-element-scroll-parent-element.d.ts +2 -0
  86. package/src/lib/guards/is-element-scroll-parent-element.js +24 -0
  87. package/src/lib/guards/is-element-scroll-parent-element.js.map +1 -0
  88. package/src/lib/guards/is-element-window.d.ts +18 -0
  89. package/src/lib/guards/is-element-window.js +22 -0
  90. package/src/lib/guards/is-element-window.js.map +1 -0
  91. package/src/lib/guards/is-keyboard-event.d.ts +18 -0
  92. package/src/lib/guards/is-keyboard-event.js +26 -0
  93. package/src/lib/guards/is-keyboard-event.js.map +1 -0
  94. package/src/lib/guards/is-node-element.d.ts +2 -0
  95. package/src/lib/guards/is-node-element.js +23 -0
  96. package/src/lib/guards/is-node-element.js.map +1 -0
  97. package/src/lib/guards/is-node-object.d.ts +18 -0
  98. package/src/lib/guards/is-node-object.js +21 -0
  99. package/src/lib/guards/is-node-object.js.map +1 -0
  100. package/src/lib/guards/is-node-shadow-root.d.ts +2 -0
  101. package/src/lib/guards/is-node-shadow-root.js +27 -0
  102. package/src/lib/guards/is-node-shadow-root.js.map +1 -0
  103. package/src/lib/guards/is-node-table-element.d.ts +2 -0
  104. package/src/lib/guards/is-node-table-element.js +26 -0
  105. package/src/lib/guards/is-node-table-element.js.map +1 -0
  106. package/src/lib/guards/is-node-window-document.d.ts +18 -0
  107. package/src/lib/guards/is-node-window-document.js +23 -0
  108. package/src/lib/guards/is-node-window-document.js.map +1 -0
  109. package/src/lib/guards/is-svg-element.d.ts +2 -0
  110. package/src/lib/guards/is-svg-element.js +22 -0
  111. package/src/lib/guards/is-svg-element.js.map +1 -0
  112. package/src/lib/guards/is-touch-event.d.ts +18 -0
  113. package/src/lib/guards/is-touch-event.js +26 -0
  114. package/src/lib/guards/is-touch-event.js.map +1 -0
@@ -0,0 +1,113 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Aglyn LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */ import { getElementClientRectBounding } from "./get-element-client-rect-bounding.js";
17
+ /**
18
+ * Where an element actually is, as the set of boxes it really occupies
19
+ * (AGL-2486).
20
+ *
21
+ * ## The defect this exists for
22
+ *
23
+ * The besigner draws selection, hover, the drag affordance and the
24
+ * collaborator selection boxes from element geometry. Taking that from ONE
25
+ * `getBoundingClientRect()` is right for a block. For an inline run that has
26
+ * wrapped it is not merely imprecise — it is a different shape.
27
+ * An inline element is a set of line fragments; its bounding rect is their
28
+ * union, which covers the empty space to the right of a short last line, and
29
+ * — when the run starts mid-line — the whole left gutter of the first line,
30
+ * where a *sibling's* text is. So the outline both fails to wrap what the
31
+ * element is and claims pixels that belong to something else.
32
+ *
33
+ * ## Why per-fragment rather than the union
34
+ *
35
+ * A union box is one element and cheap, and for HOVER it is arguably honest.
36
+ * But selection is a persistent statement about what the panels on the right
37
+ * are editing, and a union box makes that statement about pixels the element
38
+ * does not own. That is the same lie in a smaller form. Per-fragment is what
39
+ * a browser's own selection highlight does, and it is the only shape that is
40
+ * true at every wrap.
41
+ *
42
+ * ## Blocks are not routed through a fragment path
43
+ *
44
+ * The overwhelming majority of canvas nodes are blocks, and their geometry is
45
+ * correct today. When the element yields at most one client rect this returns
46
+ * the union OBJECT ITSELF for `fragments[0]`, `first` and `union` — the same
47
+ * value the old single-rect code produced, from the same call. Blocks do not
48
+ * take a different code path that merely happens to agree; there is nothing
49
+ * for them to disagree with. `get-element-fragment-rects.spec.ts` pins that.
50
+ *
51
+ * ## The shadow boundary and the device preview
52
+ *
53
+ * `getClientRects()` is a LAYOUT query on `Element`, not a tree lookup, so it
54
+ * reads identically for an element inside the canvas's CLOSED shadow root —
55
+ * verified in the running besigner on 2026-08-23, where a wrapped
56
+ * `<aglyn-text>` inside the closed root returned 3 fragments while its
57
+ * `getBoundingClientRect()` returned their union. This is unlike
58
+ * `elementFromPoint`, which retargets to the host because it returns a node
59
+ * from the light tree.
60
+ *
61
+ * Both calls return coordinates in the same viewport space with every
62
+ * ancestor transform already applied, so the artboard's device preview — and
63
+ * any future pan/zoom transform — needs no handling here, exactly as it
64
+ * needed none for the single rect.
65
+ */ export function getElementFragmentRects(element) {
66
+ const union = getElementClientRectBounding(element);
67
+ const list = element && typeof element.getClientRects === 'function' ? element.getClientRects() : null;
68
+ // No layout, or a single fragment: the union IS the answer, and it is the
69
+ // very same value the pre-AGL-2486 code drew from. Blocks land here.
70
+ if (!list || list.length <= 1) {
71
+ return {
72
+ fragments: [
73
+ union
74
+ ],
75
+ union,
76
+ first: union
77
+ };
78
+ }
79
+ const fragments = [];
80
+ for(let index = 0; index < list.length; index += 1){
81
+ const rect = list[index];
82
+ // A wrapped run can report degenerate boxes — a zero-width rect at a soft
83
+ // break, or a zero-height one for a collapsed line. Drawing chrome on
84
+ // those produces a stray hairline next to the real outline, which reads
85
+ // as a second selected thing.
86
+ if (!(rect.width > 0) || !(rect.height > 0)) continue;
87
+ fragments.push({
88
+ width: rect.width,
89
+ height: rect.height,
90
+ top: rect.top,
91
+ right: rect.right,
92
+ bottom: rect.bottom,
93
+ left: rect.left,
94
+ x: rect.left,
95
+ y: rect.top
96
+ });
97
+ }
98
+ if (!fragments.length) return {
99
+ fragments: [
100
+ union
101
+ ],
102
+ union,
103
+ first: union
104
+ };
105
+ return {
106
+ fragments,
107
+ union,
108
+ first: fragments[0]
109
+ };
110
+ }
111
+ export default getElementFragmentRects;
112
+
113
+ //# sourceMappingURL=get-element-fragment-rects.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../libs/shared/util/dom/src/lib/get-element-fragment-rects.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport {\n type BoundingClientRect,\n getElementClientRectBounding,\n} from './get-element-client-rect-bounding'\n\nexport interface ElementFragmentRects {\n /**\n * One box per LINE FRAGMENT, in viewport pixels, in content order.\n *\n * A block has exactly one. An inline run that has wrapped has one per line\n * it occupies, and no single rectangle describes it.\n */\n fragments: BoundingClientRect[]\n /**\n * The union of `fragments` — by definition identical to\n * `getBoundingClientRect()`, which the CSSOM spec defines as the union of\n * `getClientRects()`.\n */\n union: BoundingClientRect\n /**\n * The fragment the run STARTS on, i.e. `fragments[0]`.\n *\n * This is the anchor for anything that must sit at \"the element\", because\n * the union's top-left can be a point the element does not occupy: an\n * inline run that begins mid-line and wraps has a union whose left edge\n * comes from the SECOND line, so chrome placed there floats over a sibling\n * rather than over the element it names.\n */\n first: BoundingClientRect\n}\n\n/**\n * Where an element actually is, as the set of boxes it really occupies\n * (AGL-2486).\n *\n * ## The defect this exists for\n *\n * The besigner draws selection, hover, the drag affordance and the\n * collaborator selection boxes from element geometry. Taking that from ONE\n * `getBoundingClientRect()` is right for a block. For an inline run that has\n * wrapped it is not merely imprecise — it is a different shape.\n * An inline element is a set of line fragments; its bounding rect is their\n * union, which covers the empty space to the right of a short last line, and\n * — when the run starts mid-line — the whole left gutter of the first line,\n * where a *sibling's* text is. So the outline both fails to wrap what the\n * element is and claims pixels that belong to something else.\n *\n * ## Why per-fragment rather than the union\n *\n * A union box is one element and cheap, and for HOVER it is arguably honest.\n * But selection is a persistent statement about what the panels on the right\n * are editing, and a union box makes that statement about pixels the element\n * does not own. That is the same lie in a smaller form. Per-fragment is what\n * a browser's own selection highlight does, and it is the only shape that is\n * true at every wrap.\n *\n * ## Blocks are not routed through a fragment path\n *\n * The overwhelming majority of canvas nodes are blocks, and their geometry is\n * correct today. When the element yields at most one client rect this returns\n * the union OBJECT ITSELF for `fragments[0]`, `first` and `union` — the same\n * value the old single-rect code produced, from the same call. Blocks do not\n * take a different code path that merely happens to agree; there is nothing\n * for them to disagree with. `get-element-fragment-rects.spec.ts` pins that.\n *\n * ## The shadow boundary and the device preview\n *\n * `getClientRects()` is a LAYOUT query on `Element`, not a tree lookup, so it\n * reads identically for an element inside the canvas's CLOSED shadow root —\n * verified in the running besigner on 2026-08-23, where a wrapped\n * `<aglyn-text>` inside the closed root returned 3 fragments while its\n * `getBoundingClientRect()` returned their union. This is unlike\n * `elementFromPoint`, which retargets to the host because it returns a node\n * from the light tree.\n *\n * Both calls return coordinates in the same viewport space with every\n * ancestor transform already applied, so the artboard's device preview — and\n * any future pan/zoom transform — needs no handling here, exactly as it\n * needed none for the single rect.\n */\nexport function getElementFragmentRects(\n element: Element | null | undefined,\n): ElementFragmentRects {\n const union = getElementClientRectBounding(element as Element)\n\n const list =\n element && typeof (element as Element).getClientRects === 'function'\n ? (element as Element).getClientRects()\n : null\n\n // No layout, or a single fragment: the union IS the answer, and it is the\n // very same value the pre-AGL-2486 code drew from. Blocks land here.\n if (!list || list.length <= 1) {\n return { fragments: [union], union, first: union }\n }\n\n const fragments: BoundingClientRect[] = []\n for (let index = 0; index < list.length; index += 1) {\n const rect = list[index]\n // A wrapped run can report degenerate boxes — a zero-width rect at a soft\n // break, or a zero-height one for a collapsed line. Drawing chrome on\n // those produces a stray hairline next to the real outline, which reads\n // as a second selected thing.\n if (!(rect.width > 0) || !(rect.height > 0)) continue\n fragments.push({\n width: rect.width,\n height: rect.height,\n top: rect.top,\n right: rect.right,\n bottom: rect.bottom,\n left: rect.left,\n x: rect.left,\n y: rect.top,\n })\n }\n\n if (!fragments.length) return { fragments: [union], union, first: union }\n\n return { fragments, union, first: fragments[0] }\n}\n\nexport default getElementFragmentRects\n"],"names":["getElementClientRectBounding","getElementFragmentRects","element","union","list","getClientRects","length","fragments","first","index","rect","width","height","push","top","right","bottom","left","x","y"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD,SAEEA,4BAA4B,QACvB,wCAAoC;AA4B3C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgDC,GACD,OAAO,SAASC,wBACdC,OAAmC;IAEnC,MAAMC,QAAQH,6BAA6BE;IAE3C,MAAME,OACJF,WAAW,OAAO,AAACA,QAAoBG,cAAc,KAAK,aACtD,AAACH,QAAoBG,cAAc,KACnC;IAEN,0EAA0E;IAC1E,qEAAqE;IACrE,IAAI,CAACD,QAAQA,KAAKE,MAAM,IAAI,GAAG;QAC7B,OAAO;YAAEC,WAAW;gBAACJ;aAAM;YAAEA;YAAOK,OAAOL;QAAM;IACnD;IAEA,MAAMI,YAAkC,EAAE;IAC1C,IAAK,IAAIE,QAAQ,GAAGA,QAAQL,KAAKE,MAAM,EAAEG,SAAS,EAAG;QACnD,MAAMC,OAAON,IAAI,CAACK,MAAM;QACxB,0EAA0E;QAC1E,sEAAsE;QACtE,wEAAwE;QACxE,8BAA8B;QAC9B,IAAI,CAAEC,CAAAA,KAAKC,KAAK,GAAG,CAAA,KAAM,CAAED,CAAAA,KAAKE,MAAM,GAAG,CAAA,GAAI;QAC7CL,UAAUM,IAAI,CAAC;YACbF,OAAOD,KAAKC,KAAK;YACjBC,QAAQF,KAAKE,MAAM;YACnBE,KAAKJ,KAAKI,GAAG;YACbC,OAAOL,KAAKK,KAAK;YACjBC,QAAQN,KAAKM,MAAM;YACnBC,MAAMP,KAAKO,IAAI;YACfC,GAAGR,KAAKO,IAAI;YACZE,GAAGT,KAAKI,GAAG;QACb;IACF;IAEA,IAAI,CAACP,UAAUD,MAAM,EAAE,OAAO;QAAEC,WAAW;YAACJ;SAAM;QAAEA;QAAOK,OAAOL;IAAM;IAExE,OAAO;QAAEI;QAAWJ;QAAOK,OAAOD,SAAS,CAAC,EAAE;IAAC;AACjD;AAEA,eAAeN,wBAAuB"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2022 Aglyn LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import type { VisualViewport } from '../dom';
18
+ export declare function getElementListScrollParents(element: Node, list?: Array<Element | Window>): Array<Element | Window | VisualViewport>;
19
+ export default getElementListScrollParents;
@@ -0,0 +1,38 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2022 Aglyn LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */ import { getElementParentNode } from "./get-element-parent-node.js";
17
+ import { getElementScrollParent } from "./get-element-scroll-parent.js";
18
+ import { getNodeWindow } from "./get-node-window.js";
19
+ import { isElementScrollParentElement } from "./guards/is-element-scroll-parent-element.js";
20
+ /*
21
+ given a DOM element, return the list of all scroll parents, up the list of ancesors
22
+ until we get to the top window object. This list is what we attach scroll listeners
23
+ to, because if any of these parent elements scroll, we'll need to re-calculate the
24
+ reference element's position.
25
+ */ export function getElementListScrollParents(element, list = []) {
26
+ var _element_ownerDocument;
27
+ const scrollParent = getElementScrollParent(element);
28
+ const isBody = scrollParent === ((_element_ownerDocument = element.ownerDocument) == null ? void 0 : _element_ownerDocument.body);
29
+ const win = getNodeWindow(scrollParent);
30
+ const target = isBody ? [
31
+ win
32
+ ].concat(win.visualViewport || [], isElementScrollParentElement(scrollParent) ? scrollParent : []) : scrollParent;
33
+ const updatedList = list.concat(target);
34
+ return isBody ? updatedList : updatedList.concat(getElementListScrollParents(getElementParentNode(target)));
35
+ }
36
+ export default getElementListScrollParents;
37
+
38
+ //# sourceMappingURL=get-element-list-scroll-parents.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../libs/shared/util/dom/src/lib/get-element-list-scroll-parents.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2022 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n\nimport type {VisualViewport} from '../dom'\nimport {getElementParentNode} from './get-element-parent-node'\nimport {getElementScrollParent} from './get-element-scroll-parent'\nimport {getNodeWindow} from './get-node-window'\nimport {isElementScrollParentElement} from './guards/is-element-scroll-parent-element'\n\n/*\n given a DOM element, return the list of all scroll parents, up the list of ancesors\n until we get to the top window object. This list is what we attach scroll listeners\n to, because if any of these parent elements scroll, we'll need to re-calculate the\n reference element's position.\n */\nexport function getElementListScrollParents(\n element: Node,\n list: Array<Element | Window> = [],\n): Array<Element | Window | VisualViewport> {\n const scrollParent = getElementScrollParent(element)\n const isBody = scrollParent === element.ownerDocument?.body\n const win = getNodeWindow(scrollParent)\n const target = isBody\n ? [win].concat(\n win.visualViewport || [] as any,\n isElementScrollParentElement(scrollParent) ? scrollParent : [] as any,\n )\n : scrollParent\n const updatedList = list.concat(target)\n\n return isBody\n ? updatedList\n : // $FlowFixMe[incompatible-call]: isBody tells us target will be an HTMLElement here\n updatedList.concat(getElementListScrollParents(getElementParentNode(target as Element)) as any)\n}\n\nexport default getElementListScrollParents\n"],"names":["getElementParentNode","getElementScrollParent","getNodeWindow","isElementScrollParentElement","getElementListScrollParents","element","list","scrollParent","isBody","ownerDocument","body","win","target","concat","visualViewport","updatedList"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAID,SAAQA,oBAAoB,QAAO,+BAA2B;AAC9D,SAAQC,sBAAsB,QAAO,iCAA6B;AAClE,SAAQC,aAAa,QAAO,uBAAmB;AAC/C,SAAQC,4BAA4B,QAAO,+CAA2C;AAEtF;;;;;CAKC,GACD,OAAO,SAASC,4BACdC,OAAa,EACbC,OAAgC,EAAE;QAGFD;IADhC,MAAME,eAAeN,uBAAuBI;IAC5C,MAAMG,SAASD,mBAAiBF,yBAAAA,QAAQI,aAAa,qBAArBJ,uBAAuBK,IAAI;IAC3D,MAAMC,MAAMT,cAAcK;IAC1B,MAAMK,SAASJ,SACX;QAACG;KAAI,CAACE,MAAM,CACZF,IAAIG,cAAc,IAAI,EAAE,EACxBX,6BAA6BI,gBAAgBA,eAAe,EAAE,IAE9DA;IACJ,MAAMQ,cAAcT,KAAKO,MAAM,CAACD;IAEhC,OAAOJ,SACHO,cAEFA,YAAYF,MAAM,CAACT,4BAA4BJ,qBAAqBY;AACxE;AAEA,eAAeR,4BAA2B"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2021 Aglyn LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ export declare function getElementNodeName(element?: Node | Window): string;
18
+ export default getElementNodeName;
@@ -0,0 +1,21 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2021 Aglyn LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */ export function getElementNodeName(element) {
17
+ return element ? (element['nodeName'] || '').toLowerCase() : null;
18
+ }
19
+ export default getElementNodeName;
20
+
21
+ //# sourceMappingURL=get-element-node-name.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../libs/shared/util/dom/src/lib/get-element-node-name.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2021 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n\nexport function getElementNodeName(element?: Node | Window): string {\n return element ? (element['nodeName'] || '').toLowerCase() : null\n}\n\nexport default getElementNodeName\n"],"names":["getElementNodeName","element","toLowerCase"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAGD,OAAO,SAASA,mBAAmBC,OAAuB;IACxD,OAAOA,UAAU,AAACA,CAAAA,OAAO,CAAC,WAAW,IAAI,EAAC,EAAGC,WAAW,KAAK;AAC/D;AAEA,eAAeF,mBAAkB"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2022 Aglyn LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ export declare function getElementOffsetParent(element: Element): (Window & typeof globalThis) | Element;
18
+ export default getElementOffsetParent;
@@ -0,0 +1,81 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2022 Aglyn LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */ import { getElementComputedStyle } from "./get-element-computed-style.js";
17
+ import { getElementNodeName } from "./get-element-node-name.js";
18
+ import { getElementParentNode } from "./get-element-parent-node.js";
19
+ import { getNodeWindow } from "./get-node-window.js";
20
+ import { isElementHTMLElement } from "./guards/is-element-html-element.js";
21
+ import { isNodeTableElement } from "./guards/is-node-table-element.js";
22
+ function getTrueOffsetParent(element) {
23
+ if (!isElementHTMLElement(element) || // https://github.com/popperjs/popper-core/issues/837
24
+ getElementComputedStyle(element).position === 'fixed') {
25
+ return null;
26
+ }
27
+ return element['offsetParent'];
28
+ }
29
+ // `.offsetParent` reports `null` for fixed elements, while absolute elements
30
+ // return the containing block
31
+ function getContainingBlock(element) {
32
+ const isFirefox = navigator.userAgent.toLowerCase().indexOf('firefox') !== -1;
33
+ const isIE = navigator.userAgent.indexOf('Trident') !== -1;
34
+ if (isIE && isElementHTMLElement(element)) {
35
+ // In IE 9, 10 and 11 fixed elements containing block is always established by the viewport
36
+ const elementCss = getElementComputedStyle(element);
37
+ if (elementCss.position === 'fixed') {
38
+ return null;
39
+ }
40
+ }
41
+ let currentNode = getElementParentNode(element);
42
+ while(isElementHTMLElement(currentNode) && [
43
+ 'html',
44
+ 'body'
45
+ ].indexOf(getElementNodeName(currentNode)) < 0){
46
+ const css = getElementComputedStyle(currentNode);
47
+ // This is non-exhaustive but covers the most common CSS properties that
48
+ // create a containing block.
49
+ // https://developer.mozilla.org/en-US/docs/Web/CSS/Containing_block#identifying_the_containing_block
50
+ if (css.transform !== 'none' || css.perspective !== 'none' || css.contain === 'paint' || [
51
+ 'transform',
52
+ 'perspective'
53
+ ].indexOf(css.willChange) !== -1 || isFirefox && css.willChange === 'filter' || isFirefox && css.filter && css.filter !== 'none') {
54
+ return currentNode;
55
+ } else {
56
+ currentNode = currentNode.parentNode;
57
+ }
58
+ }
59
+ return null;
60
+ }
61
+ function getElementPosition(element) {
62
+ return getElementComputedStyle(element).position;
63
+ }
64
+ // Gets the closest ancestor positioned element. Handles some edge cases,
65
+ // such as table ancestors and cross browser bugs.
66
+ export function getElementOffsetParent(element) {
67
+ const window = getNodeWindow(element);
68
+ const isStaticPos = (el)=>getElementPosition(el) === 'static';
69
+ let offsetParent = getTrueOffsetParent(element);
70
+ while(offsetParent && isNodeTableElement(offsetParent) && isStaticPos(offsetParent)){
71
+ offsetParent = getTrueOffsetParent(offsetParent);
72
+ }
73
+ const nodeName = getElementNodeName(offsetParent), isHtmlEl = nodeName === 'html', isBodyElem = nodeName === 'body';
74
+ if (offsetParent && isHtmlEl || isBodyElem && isStaticPos(offsetParent)) {
75
+ return window;
76
+ }
77
+ return offsetParent || getContainingBlock(element) || window;
78
+ }
79
+ export default getElementOffsetParent;
80
+
81
+ //# sourceMappingURL=get-element-offset-parent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../libs/shared/util/dom/src/lib/get-element-offset-parent.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2022 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n\nimport {getElementComputedStyle} from './get-element-computed-style'\nimport {getElementNodeName} from './get-element-node-name'\nimport {getElementParentNode} from './get-element-parent-node'\nimport {getNodeWindow} from './get-node-window'\nimport {isElementHTMLElement} from './guards/is-element-html-element'\nimport {isNodeTableElement} from './guards/is-node-table-element'\n\n\nfunction getTrueOffsetParent(element: Element): Element {\n if (\n !isElementHTMLElement(element) ||\n // https://github.com/popperjs/popper-core/issues/837\n getElementComputedStyle(element).position === 'fixed'\n ) {\n return null\n }\n\n return element['offsetParent']\n}\n\n// `.offsetParent` reports `null` for fixed elements, while absolute elements\n// return the containing block\nfunction getContainingBlock(element: Element) {\n const isFirefox = navigator.userAgent.toLowerCase().indexOf('firefox') !== -1\n const isIE = navigator.userAgent.indexOf('Trident') !== -1\n\n if (isIE && isElementHTMLElement(element)) {\n // In IE 9, 10 and 11 fixed elements containing block is always established by the viewport\n const elementCss = getElementComputedStyle(element)\n if (elementCss.position === 'fixed') {\n return null\n }\n }\n\n let currentNode = getElementParentNode(element)\n\n while (\n isElementHTMLElement(currentNode) &&\n ['html', 'body'].indexOf(getElementNodeName(currentNode)) < 0\n ) {\n const css = getElementComputedStyle(currentNode as Element)\n\n // This is non-exhaustive but covers the most common CSS properties that\n // create a containing block.\n // https://developer.mozilla.org/en-US/docs/Web/CSS/Containing_block#identifying_the_containing_block\n if (\n css.transform !== 'none' ||\n css.perspective !== 'none' ||\n css.contain === 'paint' ||\n ['transform', 'perspective'].indexOf(css.willChange) !== -1 ||\n (isFirefox && css.willChange === 'filter') ||\n (isFirefox && css.filter && css.filter !== 'none')\n ) {\n return currentNode\n }\n else {\n currentNode = currentNode.parentNode\n }\n }\n\n return null\n}\n\nfunction getElementPosition(element: Element): string {\n return getElementComputedStyle(element).position\n}\n\n// Gets the closest ancestor positioned element. Handles some edge cases,\n// such as table ancestors and cross browser bugs.\nexport function getElementOffsetParent(element: Element) {\n const window = getNodeWindow(element)\n const isStaticPos = (el) => getElementPosition(el) === 'static'\n\n\n let offsetParent = getTrueOffsetParent(element)\n while (\n offsetParent &&\n isNodeTableElement(offsetParent) &&\n isStaticPos(offsetParent)\n ) {\n offsetParent = getTrueOffsetParent(offsetParent)\n }\n\n const nodeName = getElementNodeName(offsetParent),\n isHtmlEl = nodeName === 'html',\n isBodyElem = nodeName === 'body'\n\n if (offsetParent && isHtmlEl || (isBodyElem && isStaticPos(offsetParent))) {\n return window\n }\n\n return offsetParent || getContainingBlock(element) || window\n}\n\nexport default getElementOffsetParent\n"],"names":["getElementComputedStyle","getElementNodeName","getElementParentNode","getNodeWindow","isElementHTMLElement","isNodeTableElement","getTrueOffsetParent","element","position","getContainingBlock","isFirefox","navigator","userAgent","toLowerCase","indexOf","isIE","elementCss","currentNode","css","transform","perspective","contain","willChange","filter","parentNode","getElementPosition","getElementOffsetParent","window","isStaticPos","el","offsetParent","nodeName","isHtmlEl","isBodyElem"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAGD,SAAQA,uBAAuB,QAAO,kCAA8B;AACpE,SAAQC,kBAAkB,QAAO,6BAAyB;AAC1D,SAAQC,oBAAoB,QAAO,+BAA2B;AAC9D,SAAQC,aAAa,QAAO,uBAAmB;AAC/C,SAAQC,oBAAoB,QAAO,sCAAkC;AACrE,SAAQC,kBAAkB,QAAO,oCAAgC;AAGjE,SAASC,oBAAoBC,OAAgB;IAC3C,IACE,CAACH,qBAAqBG,YACtB,qDAAqD;IACrDP,wBAAwBO,SAASC,QAAQ,KAAK,SAC9C;QACA,OAAO;IACT;IAEA,OAAOD,OAAO,CAAC,eAAe;AAChC;AAEA,6EAA6E;AAC7E,8BAA8B;AAC9B,SAASE,mBAAmBF,OAAgB;IAC1C,MAAMG,YAAYC,UAAUC,SAAS,CAACC,WAAW,GAAGC,OAAO,CAAC,eAAe,CAAC;IAC5E,MAAMC,OAAOJ,UAAUC,SAAS,CAACE,OAAO,CAAC,eAAe,CAAC;IAEzD,IAAIC,QAAQX,qBAAqBG,UAAU;QACzC,2FAA2F;QAC3F,MAAMS,aAAahB,wBAAwBO;QAC3C,IAAIS,WAAWR,QAAQ,KAAK,SAAS;YACnC,OAAO;QACT;IACF;IAEA,IAAIS,cAAcf,qBAAqBK;IAEvC,MACEH,qBAAqBa,gBACrB;QAAC;QAAQ;KAAO,CAACH,OAAO,CAACb,mBAAmBgB,gBAAgB,EAC1D;QACF,MAAMC,MAAMlB,wBAAwBiB;QAEpC,wEAAwE;QACxE,6BAA6B;QAC7B,qGAAqG;QACrG,IACEC,IAAIC,SAAS,KAAK,UAClBD,IAAIE,WAAW,KAAK,UACpBF,IAAIG,OAAO,KAAK,WAChB;YAAC;YAAa;SAAc,CAACP,OAAO,CAACI,IAAII,UAAU,MAAM,CAAC,KACzDZ,aAAaQ,IAAII,UAAU,KAAK,YAChCZ,aAAaQ,IAAIK,MAAM,IAAIL,IAAIK,MAAM,KAAK,QAC3C;YACA,OAAON;QACT,OACK;YACHA,cAAcA,YAAYO,UAAU;QACtC;IACF;IAEA,OAAO;AACT;AAEA,SAASC,mBAAmBlB,OAAgB;IAC1C,OAAOP,wBAAwBO,SAASC,QAAQ;AAClD;AAEA,yEAAyE;AACzE,kDAAkD;AAClD,OAAO,SAASkB,uBAAuBnB,OAAgB;IACrD,MAAMoB,SAASxB,cAAcI;IAC7B,MAAMqB,cAAc,CAACC,KAAOJ,mBAAmBI,QAAQ;IAGvD,IAAIC,eAAexB,oBAAoBC;IACvC,MACEuB,gBACAzB,mBAAmByB,iBACnBF,YAAYE,cACV;QACFA,eAAexB,oBAAoBwB;IACrC;IAEA,MAAMC,WAAW9B,mBAAmB6B,eAClCE,WAAWD,aAAa,QACxBE,aAAaF,aAAa;IAE5B,IAAID,gBAAgBE,YAAaC,cAAcL,YAAYE,eAAgB;QACzE,OAAOH;IACT;IAEA,OAAOG,gBAAgBrB,mBAAmBF,YAAYoB;AACxD;AAEA,eAAeD,uBAAsB"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2022 Aglyn LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ export declare function getElementParentNode(element: Node | ShadowRoot): Node;
18
+ export default getElementParentNode;
@@ -0,0 +1,31 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2022 Aglyn LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */ import { getElementDocumentElement } from "./get-element-document-element.js";
17
+ import { getElementNodeName } from "./get-element-node-name.js";
18
+ import { isNodeShadowRoot } from "./guards/is-node-shadow-root.js";
19
+ export function getElementParentNode(element) {
20
+ if (getElementNodeName(element) === 'html') {
21
+ return element;
22
+ }
23
+ return(// this is a quicker (but less type safe) way to save quite some bytes from the bundle
24
+ // ShadowDom
25
+ element['assignedSlot'] || // step into the shadow DOM of the parent of a slotted node
26
+ element.parentNode || // DOM Element
27
+ (isNodeShadowRoot(element) ? element.host : null) || getElementDocumentElement(element));
28
+ }
29
+ export default getElementParentNode;
30
+
31
+ //# sourceMappingURL=get-element-parent-node.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../libs/shared/util/dom/src/lib/get-element-parent-node.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2022 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {getElementDocumentElement} from './get-element-document-element'\nimport {getElementNodeName} from './get-element-node-name'\nimport {isNodeShadowRoot} from './guards/is-node-shadow-root'\n\n\nexport function getElementParentNode(element: Node | ShadowRoot): Node {\n if (getElementNodeName(element) === 'html') {\n return element\n }\n\n return (\n // this is a quicker (but less type safe) way to save quite some bytes from the bundle\n // ShadowDom\n (element['assignedSlot'] || // step into the shadow DOM of the parent of a slotted node\n element.parentNode || // DOM Element\n (\n isNodeShadowRoot(element) ? element.host : null) || getElementDocumentElement(element as Element, // fallback\n ))\n );\n}\n\nexport default getElementParentNode\n"],"names":["getElementDocumentElement","getElementNodeName","isNodeShadowRoot","getElementParentNode","element","parentNode","host"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAAQA,yBAAyB,QAAO,oCAAgC;AACxE,SAAQC,kBAAkB,QAAO,6BAAyB;AAC1D,SAAQC,gBAAgB,QAAO,kCAA8B;AAG7D,OAAO,SAASC,qBAAqBC,OAA0B;IAC7D,IAAIH,mBAAmBG,aAAa,QAAQ;QAC1C,OAAOA;IACT;IAEA,OACE,sFAAsF;IACtF,YAAY;IACXA,OAAO,CAAC,eAAe,IAAI,2DAA2D;IACvFA,QAAQC,UAAU,IAAI,cAAc;IAElCH,CAAAA,iBAAiBE,WAAWA,QAAQE,IAAI,GAAG,IAAG,KAAMN,0BAA0BI;AAGpF;AAEA,eAAeD,qBAAoB"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2022 Aglyn LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import type { ClientRectObject, Rect } from '../dom';
18
+ export declare function getElementRectAsClientRect(rect: Rect): ClientRectObject;
19
+ export default getElementRectAsClientRect;
@@ -0,0 +1,27 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2022 Aglyn LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */ import { _ as _extends } from "@swc/helpers/_/_extends";
17
+ export function getElementRectAsClientRect(rect) {
18
+ return _extends({}, rect, {
19
+ left: rect.x,
20
+ top: rect.y,
21
+ right: rect.x + rect.width,
22
+ bottom: rect.y + rect.height
23
+ });
24
+ }
25
+ export default getElementRectAsClientRect;
26
+
27
+ //# sourceMappingURL=get-element-rect-as-client-rect.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../libs/shared/util/dom/src/lib/get-element-rect-as-client-rect.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2022 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type {ClientRectObject, Rect} from '../dom'\n\n\nexport function getElementRectAsClientRect(rect: Rect): ClientRectObject {\n return {\n ...rect,\n left: rect.x,\n top: rect.y,\n right: rect.x + rect.width,\n bottom: rect.y + rect.height,\n }\n}\nexport default getElementRectAsClientRect\n"],"names":["getElementRectAsClientRect","rect","left","x","top","y","right","width","bottom","height"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC;AAKD,OAAO,SAASA,2BAA2BC,IAAU;IACnD,OAAO,aACFA;QACHC,MAAMD,KAAKE,CAAC;QACZC,KAAKH,KAAKI,CAAC;QACXC,OAAOL,KAAKE,CAAC,GAAGF,KAAKM,KAAK;QAC1BC,QAAQP,KAAKI,CAAC,GAAGJ,KAAKQ,MAAM;;AAEhC;AACA,eAAeT,2BAA0B"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2022 Aglyn LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ export declare function getElementScrollParent(node: Node): HTMLElement;
18
+ export default getElementScrollParent;
@@ -0,0 +1,36 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2022 Aglyn LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */ import { getElementNodeName } from "./get-element-node-name.js";
17
+ import { getElementParentNode } from "./get-element-parent-node.js";
18
+ import { isElementHTMLElement } from "./guards/is-element-html-element.js";
19
+ import { isElementScrollParentElement } from "./guards/is-element-scroll-parent-element.js";
20
+ export function getElementScrollParent(node) {
21
+ if ([
22
+ 'html',
23
+ 'body',
24
+ '#document'
25
+ ].indexOf(getElementNodeName(node)) >= 0) {
26
+ // $FlowFixMe[incompatible-return]: assume body is always available
27
+ return node.ownerDocument.body;
28
+ }
29
+ if (isElementHTMLElement(node) && isElementScrollParentElement(node)) {
30
+ return node;
31
+ }
32
+ return getElementScrollParent(getElementParentNode(node));
33
+ }
34
+ export default getElementScrollParent;
35
+
36
+ //# sourceMappingURL=get-element-scroll-parent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../libs/shared/util/dom/src/lib/get-element-scroll-parent.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2022 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n\nimport {getElementNodeName} from './get-element-node-name'\nimport {getElementParentNode} from './get-element-parent-node'\nimport {isElementHTMLElement} from './guards/is-element-html-element'\nimport {isElementScrollParentElement} from './guards/is-element-scroll-parent-element'\n\n\nexport function getElementScrollParent(node: Node): HTMLElement {\n if (['html', 'body', '#document'].indexOf(getElementNodeName(node)) >= 0) {\n // $FlowFixMe[incompatible-return]: assume body is always available\n return node.ownerDocument.body\n }\n\n if (isElementHTMLElement(node) && isElementScrollParentElement(node as HTMLElement)) {\n return node as HTMLElement\n }\n\n return getElementScrollParent(getElementParentNode(node))\n}\n\nexport default getElementScrollParent\n"],"names":["getElementNodeName","getElementParentNode","isElementHTMLElement","isElementScrollParentElement","getElementScrollParent","node","indexOf","ownerDocument","body"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAGD,SAAQA,kBAAkB,QAAO,6BAAyB;AAC1D,SAAQC,oBAAoB,QAAO,+BAA2B;AAC9D,SAAQC,oBAAoB,QAAO,sCAAkC;AACrE,SAAQC,4BAA4B,QAAO,+CAA2C;AAGtF,OAAO,SAASC,uBAAuBC,IAAU;IAC/C,IAAI;QAAC;QAAQ;QAAQ;KAAY,CAACC,OAAO,CAACN,mBAAmBK,UAAU,GAAG;QACxE,mEAAmE;QACnE,OAAOA,KAAKE,aAAa,CAACC,IAAI;IAChC;IAEA,IAAIN,qBAAqBG,SAASF,6BAA6BE,OAAsB;QACnF,OAAOA;IACT;IAEA,OAAOD,uBAAuBH,qBAAqBI;AACrD;AAEA,eAAeD,uBAAsB"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2021 Aglyn LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ export declare function getElementViewportRect(element: Element): {
18
+ width: number;
19
+ height: number;
20
+ x: number;
21
+ y: number;
22
+ };
23
+ export default getElementViewportRect;
@@ -0,0 +1,57 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2021 Aglyn LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */ import { getElementDocumentElement } from "./get-element-document-element.js";
17
+ import { getElementWindowScrollBarX } from "./get-element-window-scroll-bar-x.js";
18
+ import { getNodeWindow } from "./get-node-window.js";
19
+ export function getElementViewportRect(element) {
20
+ const win = getNodeWindow(element);
21
+ const html = getElementDocumentElement(element);
22
+ const visualViewport = win.visualViewport;
23
+ let width = html.clientWidth;
24
+ let height = html.clientHeight;
25
+ let x = 0;
26
+ let y = 0;
27
+ // NB: This isn't supported on iOS <= 12. If the keyboard is open, the popper
28
+ // can be obscured underneath it.
29
+ // Also, `html.clientHeight` adds the bottom bar height in Safari iOS, even
30
+ // if it isn't open, so if this isn't available, the popper will be detected
31
+ // to overflow the bottom of the screen too early.
32
+ if (visualViewport) {
33
+ width = visualViewport.width;
34
+ height = visualViewport.height;
35
+ // Uses Layout Viewport (like Chrome; Safari does not currently)
36
+ // In Chrome, it returns a value very close to 0 (+/-) but contains rounding
37
+ // errors due to floating point numbers, so we need to check precision.
38
+ // Safari returns a number <= 0, usually < -1 when pinch-zoomed
39
+ // Feature detection fails in mobile emulation mode in Chrome.
40
+ // Math.abs(win.innerWidth / visualViewport.scale - visualViewport.width) <
41
+ // 0.001
42
+ // Fallback here: "Not Safari" userAgent
43
+ if (!/^((?!chrome|android).)*safari/i.test(navigator.userAgent)) {
44
+ x = visualViewport.offsetLeft;
45
+ y = visualViewport.offsetTop;
46
+ }
47
+ }
48
+ return {
49
+ width,
50
+ height,
51
+ x: x + getElementWindowScrollBarX(element),
52
+ y
53
+ };
54
+ }
55
+ export default getElementViewportRect;
56
+
57
+ //# sourceMappingURL=get-element-viewport-rect.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../libs/shared/util/dom/src/lib/get-element-viewport-rect.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2021 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n\nimport {getElementDocumentElement} from './get-element-document-element'\nimport {getElementWindowScrollBarX} from './get-element-window-scroll-bar-x'\nimport {getNodeWindow} from './get-node-window'\n\n\nexport function getElementViewportRect(element: Element) {\n const win = getNodeWindow(element)\n const html = getElementDocumentElement(element)\n const visualViewport = win.visualViewport\n\n\n let width = html.clientWidth\n let height = html.clientHeight\n let x = 0\n let y = 0\n\n // NB: This isn't supported on iOS <= 12. If the keyboard is open, the popper\n // can be obscured underneath it.\n // Also, `html.clientHeight` adds the bottom bar height in Safari iOS, even\n // if it isn't open, so if this isn't available, the popper will be detected\n // to overflow the bottom of the screen too early.\n if (visualViewport) {\n width = visualViewport.width\n height = visualViewport.height\n\n // Uses Layout Viewport (like Chrome; Safari does not currently)\n // In Chrome, it returns a value very close to 0 (+/-) but contains rounding\n // errors due to floating point numbers, so we need to check precision.\n // Safari returns a number <= 0, usually < -1 when pinch-zoomed\n\n // Feature detection fails in mobile emulation mode in Chrome.\n // Math.abs(win.innerWidth / visualViewport.scale - visualViewport.width) <\n // 0.001\n // Fallback here: \"Not Safari\" userAgent\n if (!/^((?!chrome|android).)*safari/i.test(navigator.userAgent)) {\n x = visualViewport.offsetLeft\n y = visualViewport.offsetTop\n }\n }\n\n return {\n width,\n height,\n x: x + getElementWindowScrollBarX(element),\n y,\n }\n}\nexport default getElementViewportRect\n"],"names":["getElementDocumentElement","getElementWindowScrollBarX","getNodeWindow","getElementViewportRect","element","win","html","visualViewport","width","clientWidth","height","clientHeight","x","y","test","navigator","userAgent","offsetLeft","offsetTop"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAGD,SAAQA,yBAAyB,QAAO,oCAAgC;AACxE,SAAQC,0BAA0B,QAAO,uCAAmC;AAC5E,SAAQC,aAAa,QAAO,uBAAmB;AAG/C,OAAO,SAASC,uBAAuBC,OAAgB;IACrD,MAAMC,MAAMH,cAAcE;IAC1B,MAAME,OAAON,0BAA0BI;IACvC,MAAMG,iBAAiBF,IAAIE,cAAc;IAGzC,IAAIC,QAAQF,KAAKG,WAAW;IAC5B,IAAIC,SAASJ,KAAKK,YAAY;IAC9B,IAAIC,IAAI;IACR,IAAIC,IAAI;IAER,6EAA6E;IAC7E,iCAAiC;IACjC,2EAA2E;IAC3E,4EAA4E;IAC5E,kDAAkD;IAClD,IAAIN,gBAAgB;QAClBC,QAAQD,eAAeC,KAAK;QAC5BE,SAASH,eAAeG,MAAM;QAE9B,gEAAgE;QAChE,4EAA4E;QAC5E,uEAAuE;QACvE,+DAA+D;QAE/D,8DAA8D;QAC9D,2EAA2E;QAC3E,QAAQ;QACR,wCAAwC;QACxC,IAAI,CAAC,iCAAiCI,IAAI,CAACC,UAAUC,SAAS,GAAG;YAC/DJ,IAAIL,eAAeU,UAAU;YAC7BJ,IAAIN,eAAeW,SAAS;QAC9B;IACF;IAEA,OAAO;QACLV;QACAE;QACAE,GAAGA,IAAIX,2BAA2BG;QAClCS;IACF;AACF;AACA,eAAeV,uBAAsB"}