@zanichelli/albe-web-components 18.6.1 → 18.6.3-RC

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 (187) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/dist/cjs/{index-c48948bf.js → index-0d3de93e.js} +2 -2
  3. package/dist/cjs/{index-c48948bf.js.map → index-0d3de93e.js.map} +1 -1
  4. package/dist/cjs/index.cjs.js +1 -1
  5. package/dist/cjs/loader.cjs.js +1 -1
  6. package/dist/cjs/{utils-93961cb6.js → utils-3dc316f8.js} +56 -1
  7. package/dist/cjs/utils-3dc316f8.js.map +1 -0
  8. package/dist/cjs/web-components-library.cjs.js +1 -1
  9. package/dist/cjs/z-anchor-navigation.cjs.entry.js +1 -1
  10. package/dist/cjs/z-anchor-navigation.cjs.entry.js.map +1 -1
  11. package/dist/cjs/z-app-header_12.cjs.entry.js +1 -1
  12. package/dist/cjs/z-book-card-deprecated.cjs.entry.js +1 -1
  13. package/dist/cjs/z-breadcrumb.cjs.entry.js +1 -1
  14. package/dist/cjs/z-card.cjs.entry.js +1 -1
  15. package/dist/cjs/z-card.cjs.entry.js.map +1 -1
  16. package/dist/cjs/z-combobox.cjs.entry.js +1 -1
  17. package/dist/cjs/z-menu.cjs.entry.js +1 -1
  18. package/dist/cjs/z-myz-card-info.cjs.entry.js +1 -1
  19. package/dist/cjs/z-myz-list-item.cjs.entry.js +1 -1
  20. package/dist/cjs/z-popover.cjs.entry.js +232 -264
  21. package/dist/cjs/z-popover.cjs.entry.js.map +1 -1
  22. package/dist/cjs/z-select.cjs.entry.js +4 -6
  23. package/dist/cjs/z-select.cjs.entry.js.map +1 -1
  24. package/dist/cjs/z-skip-to-content.cjs.entry.js +1 -1
  25. package/dist/cjs/z-slideshow.cjs.entry.js +1 -1
  26. package/dist/cjs/z-table.cjs.entry.js +2 -2
  27. package/dist/cjs/z-toggle-switch.cjs.entry.js +1 -1
  28. package/dist/cjs/z-tr.cjs.entry.js +2 -2
  29. package/dist/collection/components/z-anchor-navigation/index.js +2 -2
  30. package/dist/collection/components/z-anchor-navigation/index.js.map +1 -1
  31. package/dist/collection/components/z-card/styles.css +4 -0
  32. package/dist/collection/components/z-popover/index.js +236 -268
  33. package/dist/collection/components/z-popover/index.js.map +1 -1
  34. package/dist/collection/components/z-popover/index.stories.js +92 -45
  35. package/dist/collection/components/z-popover/index.stories.js.map +1 -1
  36. package/dist/collection/components/z-popover/styles.css +4 -14
  37. package/dist/collection/components/z-select/index.js +4 -6
  38. package/dist/collection/components/z-select/index.js.map +1 -1
  39. package/dist/collection/utils/utils.js +53 -0
  40. package/dist/collection/utils/utils.js.map +1 -1
  41. package/dist/components/index23.js +234 -266
  42. package/dist/components/index23.js.map +1 -1
  43. package/dist/components/index24.js +1 -1
  44. package/dist/components/utils.js +55 -2
  45. package/dist/components/utils.js.map +1 -1
  46. package/dist/components/z-anchor-navigation.js +2 -2
  47. package/dist/components/z-anchor-navigation.js.map +1 -1
  48. package/dist/components/z-card.js +1 -1
  49. package/dist/components/z-card.js.map +1 -1
  50. package/dist/components/z-select.js +4 -6
  51. package/dist/components/z-select.js.map +1 -1
  52. package/dist/esm/{index-10473b87.js → index-328b69a7.js} +2 -2
  53. package/dist/esm/{index-10473b87.js.map → index-328b69a7.js.map} +1 -1
  54. package/dist/esm/index.js +1 -1
  55. package/dist/esm/loader.js +1 -1
  56. package/dist/esm/{utils-c8abef2f.js → utils-6e2be2b6.js} +55 -2
  57. package/dist/esm/utils-6e2be2b6.js.map +1 -0
  58. package/dist/esm/web-components-library.js +1 -1
  59. package/dist/esm/z-anchor-navigation.entry.js +2 -2
  60. package/dist/esm/z-anchor-navigation.entry.js.map +1 -1
  61. package/dist/esm/z-app-header_12.entry.js +1 -1
  62. package/dist/esm/z-book-card-deprecated.entry.js +1 -1
  63. package/dist/esm/z-breadcrumb.entry.js +1 -1
  64. package/dist/esm/z-card.entry.js +1 -1
  65. package/dist/esm/z-card.entry.js.map +1 -1
  66. package/dist/esm/z-combobox.entry.js +1 -1
  67. package/dist/esm/z-menu.entry.js +1 -1
  68. package/dist/esm/z-myz-card-info.entry.js +1 -1
  69. package/dist/esm/z-myz-list-item.entry.js +1 -1
  70. package/dist/esm/z-popover.entry.js +233 -265
  71. package/dist/esm/z-popover.entry.js.map +1 -1
  72. package/dist/esm/z-select.entry.js +4 -6
  73. package/dist/esm/z-select.entry.js.map +1 -1
  74. package/dist/esm/z-skip-to-content.entry.js +1 -1
  75. package/dist/esm/z-slideshow.entry.js +1 -1
  76. package/dist/esm/z-table.entry.js +2 -2
  77. package/dist/esm/z-toggle-switch.entry.js +1 -1
  78. package/dist/esm/z-tr.entry.js +2 -2
  79. package/dist/types/components/z-popover/index.d.ts +47 -45
  80. package/dist/types/components/z-popover/index.stories.d.ts +18 -7
  81. package/dist/types/components.d.ts +13 -17
  82. package/dist/types/utils/utils.d.ts +17 -0
  83. package/dist/web-components-library/index.esm.js +1 -1
  84. package/dist/web-components-library/{p-8b93bc6d.entry.js → p-01302e57.entry.js} +2 -2
  85. package/dist/web-components-library/{p-14f0bdf4.entry.js → p-1ad8810a.entry.js} +2 -2
  86. package/{www/build/p-c2ba8a6c.entry.js → dist/web-components-library/p-2e0923bd.entry.js} +2 -2
  87. package/dist/web-components-library/p-3284e37b.entry.js +2 -0
  88. package/dist/web-components-library/{p-61f76cab.js → p-43bc482a.js} +2 -2
  89. package/{www/build/p-2fb52cd0.entry.js → dist/web-components-library/p-539f99db.entry.js} +2 -2
  90. package/dist/web-components-library/p-625e2cee.js +2 -0
  91. package/dist/web-components-library/p-625e2cee.js.map +1 -0
  92. package/dist/web-components-library/p-62e1d867.entry.js +2 -0
  93. package/dist/web-components-library/p-62e1d867.entry.js.map +1 -0
  94. package/dist/web-components-library/p-63d220da.entry.js +2 -0
  95. package/dist/web-components-library/{p-8d5e3396.entry.js.map → p-63d220da.entry.js.map} +1 -1
  96. package/dist/web-components-library/{p-c8814ae1.entry.js → p-7916e0f7.entry.js} +2 -2
  97. package/{www/build/p-f5efb3fc.entry.js → dist/web-components-library/p-8bd4a2aa.entry.js} +2 -2
  98. package/dist/web-components-library/{p-c962e854.entry.js → p-8dec332e.entry.js} +2 -2
  99. package/dist/web-components-library/{p-72a7eb26.entry.js → p-966cbf03.entry.js} +2 -2
  100. package/{www/build/p-30575221.entry.js → dist/web-components-library/p-a0ed0c63.entry.js} +2 -2
  101. package/dist/web-components-library/p-b7b972c0.entry.js +2 -0
  102. package/dist/web-components-library/p-b7b972c0.entry.js.map +1 -0
  103. package/dist/web-components-library/{p-25935be3.entry.js → p-bc2f94d9.entry.js} +2 -2
  104. package/dist/web-components-library/{p-57b8bd19.entry.js → p-db9b7eb5.entry.js} +2 -2
  105. package/dist/web-components-library/p-db9b7eb5.entry.js.map +1 -0
  106. package/dist/web-components-library/p-df04a63e.entry.js +2 -0
  107. package/dist/web-components-library/p-df04a63e.entry.js.map +1 -0
  108. package/dist/web-components-library/web-components-library.esm.js +1 -1
  109. package/dist/web-components-library/web-components-library.esm.js.map +1 -1
  110. package/package.json +1 -1
  111. package/www/build/index.esm.js +1 -1
  112. package/www/build/{p-8b93bc6d.entry.js → p-01302e57.entry.js} +2 -2
  113. package/www/build/{p-14f0bdf4.entry.js → p-1ad8810a.entry.js} +2 -2
  114. package/{dist/web-components-library/p-c2ba8a6c.entry.js → www/build/p-2e0923bd.entry.js} +2 -2
  115. package/www/build/p-3284e37b.entry.js +2 -0
  116. package/www/build/{p-61f76cab.js → p-43bc482a.js} +2 -2
  117. package/{dist/web-components-library/p-2fb52cd0.entry.js → www/build/p-539f99db.entry.js} +2 -2
  118. package/www/build/p-625e2cee.js +2 -0
  119. package/www/build/p-625e2cee.js.map +1 -0
  120. package/www/build/p-62e1d867.entry.js +2 -0
  121. package/www/build/p-62e1d867.entry.js.map +1 -0
  122. package/www/build/p-63d220da.entry.js +2 -0
  123. package/www/build/{p-8d5e3396.entry.js.map → p-63d220da.entry.js.map} +1 -1
  124. package/www/build/{p-c8814ae1.entry.js → p-7916e0f7.entry.js} +2 -2
  125. package/{dist/web-components-library/p-f5efb3fc.entry.js → www/build/p-8bd4a2aa.entry.js} +2 -2
  126. package/www/build/{p-c962e854.entry.js → p-8dec332e.entry.js} +2 -2
  127. package/www/build/{p-72a7eb26.entry.js → p-966cbf03.entry.js} +2 -2
  128. package/{dist/web-components-library/p-30575221.entry.js → www/build/p-a0ed0c63.entry.js} +2 -2
  129. package/www/build/p-b7b972c0.entry.js +2 -0
  130. package/www/build/p-b7b972c0.entry.js.map +1 -0
  131. package/www/build/{p-25935be3.entry.js → p-bc2f94d9.entry.js} +2 -2
  132. package/www/build/{p-adc42c6f.js → p-c2d3e81c.js} +1 -1
  133. package/www/build/{p-57b8bd19.entry.js → p-db9b7eb5.entry.js} +2 -2
  134. package/www/build/p-db9b7eb5.entry.js.map +1 -0
  135. package/www/build/p-df04a63e.entry.js +2 -0
  136. package/www/build/p-df04a63e.entry.js.map +1 -0
  137. package/www/build/web-components-library.esm.js +1 -1
  138. package/www/build/web-components-library.esm.js.map +1 -1
  139. package/www/index.html +1 -1
  140. package/dist/cjs/utils-93961cb6.js.map +0 -1
  141. package/dist/esm/utils-c8abef2f.js.map +0 -1
  142. package/dist/web-components-library/p-37f271c8.entry.js +0 -2
  143. package/dist/web-components-library/p-37f271c8.entry.js.map +0 -1
  144. package/dist/web-components-library/p-57b8bd19.entry.js.map +0 -1
  145. package/dist/web-components-library/p-69a1a67a.entry.js +0 -2
  146. package/dist/web-components-library/p-8d5e3396.entry.js +0 -2
  147. package/dist/web-components-library/p-a06fbbc0.js +0 -2
  148. package/dist/web-components-library/p-a06fbbc0.js.map +0 -1
  149. package/dist/web-components-library/p-da30a6cb.entry.js +0 -2
  150. package/dist/web-components-library/p-da30a6cb.entry.js.map +0 -1
  151. package/dist/web-components-library/p-e1a80453.entry.js +0 -2
  152. package/dist/web-components-library/p-e1a80453.entry.js.map +0 -1
  153. package/www/build/p-37f271c8.entry.js +0 -2
  154. package/www/build/p-37f271c8.entry.js.map +0 -1
  155. package/www/build/p-57b8bd19.entry.js.map +0 -1
  156. package/www/build/p-69a1a67a.entry.js +0 -2
  157. package/www/build/p-8d5e3396.entry.js +0 -2
  158. package/www/build/p-a06fbbc0.js +0 -2
  159. package/www/build/p-a06fbbc0.js.map +0 -1
  160. package/www/build/p-da30a6cb.entry.js +0 -2
  161. package/www/build/p-da30a6cb.entry.js.map +0 -1
  162. package/www/build/p-e1a80453.entry.js +0 -2
  163. package/www/build/p-e1a80453.entry.js.map +0 -1
  164. /package/dist/web-components-library/{p-8b93bc6d.entry.js.map → p-01302e57.entry.js.map} +0 -0
  165. /package/dist/web-components-library/{p-14f0bdf4.entry.js.map → p-1ad8810a.entry.js.map} +0 -0
  166. /package/dist/web-components-library/{p-c2ba8a6c.entry.js.map → p-2e0923bd.entry.js.map} +0 -0
  167. /package/dist/web-components-library/{p-69a1a67a.entry.js.map → p-3284e37b.entry.js.map} +0 -0
  168. /package/dist/web-components-library/{p-61f76cab.js.map → p-43bc482a.js.map} +0 -0
  169. /package/dist/web-components-library/{p-2fb52cd0.entry.js.map → p-539f99db.entry.js.map} +0 -0
  170. /package/dist/web-components-library/{p-c8814ae1.entry.js.map → p-7916e0f7.entry.js.map} +0 -0
  171. /package/dist/web-components-library/{p-f5efb3fc.entry.js.map → p-8bd4a2aa.entry.js.map} +0 -0
  172. /package/dist/web-components-library/{p-c962e854.entry.js.map → p-8dec332e.entry.js.map} +0 -0
  173. /package/dist/web-components-library/{p-72a7eb26.entry.js.map → p-966cbf03.entry.js.map} +0 -0
  174. /package/dist/web-components-library/{p-30575221.entry.js.map → p-a0ed0c63.entry.js.map} +0 -0
  175. /package/dist/web-components-library/{p-25935be3.entry.js.map → p-bc2f94d9.entry.js.map} +0 -0
  176. /package/www/build/{p-8b93bc6d.entry.js.map → p-01302e57.entry.js.map} +0 -0
  177. /package/www/build/{p-14f0bdf4.entry.js.map → p-1ad8810a.entry.js.map} +0 -0
  178. /package/www/build/{p-c2ba8a6c.entry.js.map → p-2e0923bd.entry.js.map} +0 -0
  179. /package/www/build/{p-69a1a67a.entry.js.map → p-3284e37b.entry.js.map} +0 -0
  180. /package/www/build/{p-61f76cab.js.map → p-43bc482a.js.map} +0 -0
  181. /package/www/build/{p-2fb52cd0.entry.js.map → p-539f99db.entry.js.map} +0 -0
  182. /package/www/build/{p-c8814ae1.entry.js.map → p-7916e0f7.entry.js.map} +0 -0
  183. /package/www/build/{p-f5efb3fc.entry.js.map → p-8bd4a2aa.entry.js.map} +0 -0
  184. /package/www/build/{p-c962e854.entry.js.map → p-8dec332e.entry.js.map} +0 -0
  185. /package/www/build/{p-72a7eb26.entry.js.map → p-966cbf03.entry.js.map} +0 -0
  186. /package/www/build/{p-30575221.entry.js.map → p-a0ed0c63.entry.js.map} +0 -0
  187. /package/www/build/{p-25935be3.entry.js.map → p-bc2f94d9.entry.js.map} +0 -0
@@ -1,100 +1,18 @@
1
1
  import { r as registerInstance, c as createEvent, h, a as Host, g as getElement } from './index-c8ceadeb.js';
2
- import { P as PopoverPosition, g as KeyboardCode } from './index-2a6324f8.js';
2
+ import { P as PopoverPosition, g as KeyboardCode, p as Device } from './index-2a6324f8.js';
3
+ import { a as containsElement, j as findScrollableParent, g as getDevice, k as isElementVisibleInContainer } from './utils-6e2be2b6.js';
4
+ import './breakpoints-d148bfde.js';
3
5
 
4
- const stylesCss = ":host{position:absolute;display:none;min-width:calc(var(--space-unit) * 8);max-width:100%;min-height:calc(var(--space-unit) * 4);max-height:100%;align-items:center;justify-content:center;padding:var(--z-popover-padding, 0);background:var(--z-popover-theme--surface, var(--color-surface01));border-radius:var(--border-radius-small);color:var(--z-popover-theme--text, var(--color-default-text));fill:currentcolor;filter:var(--z-popover-shadow-filter, drop-shadow(0 1px 2px var(--shadow-color-base)));font-family:var(--font-family-sans);text-align:center}:host([open]:not([current-position])){visibility:hidden}:host([open][current-position]),:host([open=\"true\"][current-position]){display:flex}:host([center][current-position=\"top\"]),:host([center][current-position=\"bottom\"]){transform:translateX(-50%)}:host([center][current-position=\"right\"]),:host([center][current-position=\"left\"]){transform:translateY(-50%)}:host([current-position^=\"top\"]){margin:0 0 var(--space-unit)}:host([current-position^=\"bottom\"]){margin:var(--space-unit) 0 0}:host([current-position^=\"left\"]){margin:0 var(--space-unit) 0 0}:host([current-position^=\"right\"]){margin:0 0 0 var(--space-unit)}:host([current-position])::before{--arrow-size:6px;--arrow-edge-offset:calc(100% - var(--space-unit) - (var(--arrow-size) / 2));--arrow-center-x-offset:calc(50% - (var(--arrow-size) / 2));--arrow-center-y-offset:calc(100% - (var(--arrow-size) / 2));position:absolute;display:block;width:var(--arrow-size);height:var(--arrow-size);background:var(--z-popover-theme--surface, var(--color-surface01));content:\"\";transform:rotate(45deg)}:host([show-arrow=\"false\"])::before,:host(:not([show-arrow]))::before{display:none}:host([current-position^=\"top\"])::before{top:var(--arrow-center-y-offset)}:host([current-position^=\"bottom\"])::before{bottom:var(--arrow-center-y-offset)}:host([current-position=\"top\"])::before,:host([current-position=\"bottom\"])::before{right:var(--arrow-edge-offset)}:host([current-position=\"right\"])::before,:host([current-position=\"left\"])::before{bottom:var(--arrow-edge-offset)}:host([current-position=\"right\"])::before{right:var(--arrow-center-y-offset)}:host([current-position=\"left\"])::before{left:var(--arrow-center-y-offset)}:host([current-position=\"top_right\"])::before,:host([current-position=\"bottom_right\"])::before{right:var(--arrow-edge-offset)}:host([current-position=\"top_left\"])::before,:host([current-position=\"bottom_left\"])::before{left:var(--arrow-edge-offset)}:host([current-position=\"right_top\"])::before,:host([current-position=\"left_top\"])::before{top:var(--arrow-edge-offset)}:host([current-position=\"right_top\"])::before,:host([current-position=\"right_bottom\"])::before{right:var(--arrow-center-y-offset)}:host([current-position=\"left_top\"])::before,:host([current-position=\"left_bottom\"])::before{left:var(--arrow-center-y-offset)}:host([current-position=\"right_bottom\"])::before,:host([current-position=\"left_bottom\"])::before{bottom:var(--arrow-edge-offset)}:host([center][current-position=\"top\"])::before,:host([center][current-position=\"bottom\"])::before{right:auto;left:var(--arrow-center-x-offset)}:host([center][current-position=\"right\"])::before,:host([center][current-position=\"left\"])::before{top:var(--arrow-center-x-offset);bottom:auto}::slotted(*){overflow:auto;flex:1 auto}";
6
+ const stylesCss = ":host{position:fixed;display:none;max-width:calc(100% - var(--grid-margin) * 2);max-height:calc(100% - var(--grid-margin) * 2);padding:var(--z-popover-padding, 0);background:var(--z-popover-theme--surface, var(--color-surface01));border-radius:var(--border-radius-small);color:var(--z-popover-theme--text, var(--color-default-text));fill:currentcolor;filter:var(--z-popover-shadow-filter, drop-shadow(0 1px 2px var(--shadow-color-base)));text-align:center}:host([open]:not([current-position])){visibility:hidden}:host([open][current-position]),:host([open=\"true\"][current-position]){display:block}:host([center][current-position=\"top\"]),:host([center][current-position=\"bottom\"]){transform:translateX(-50%)}:host([center][current-position=\"right\"]),:host([center][current-position=\"left\"]){transform:translateY(-50%)}:host([current-position^=\"top\"]){margin:0 0 var(--space-unit)}:host([current-position^=\"bottom\"]){margin:var(--space-unit) 0 0}:host([current-position^=\"left\"]){margin:0 var(--space-unit) 0 0}:host([current-position^=\"right\"]){margin:0 0 0 var(--space-unit)}:host([current-position])::before{--arrow-size:6px;--arrow-edge-offset:calc(100% - var(--space-unit) - (var(--arrow-size) / 2));--arrow-center-x-offset:calc(50% - (var(--arrow-size) / 2));--arrow-center-y-offset:calc(100% - (var(--arrow-size) / 2));position:absolute;display:block;width:var(--arrow-size);height:var(--arrow-size);background:var(--z-popover-theme--surface, var(--color-surface01));content:\"\";transform:rotate(45deg)}:host([show-arrow=\"false\"])::before,:host(:not([show-arrow]))::before{display:none}:host([current-position^=\"top\"])::before{top:var(--arrow-center-y-offset)}:host([current-position^=\"bottom\"])::before{bottom:var(--arrow-center-y-offset)}:host([current-position=\"top\"])::before,:host([current-position=\"bottom\"])::before{right:var(--arrow-edge-offset)}:host([current-position=\"right\"])::before,:host([current-position=\"left\"])::before{bottom:var(--arrow-edge-offset)}:host([current-position=\"right\"])::before{right:var(--arrow-center-y-offset)}:host([current-position=\"left\"])::before{left:var(--arrow-center-y-offset)}:host([current-position=\"top_right\"])::before,:host([current-position=\"bottom_right\"])::before{right:var(--arrow-edge-offset)}:host([current-position=\"top_left\"])::before,:host([current-position=\"bottom_left\"])::before{left:var(--arrow-edge-offset)}:host([current-position=\"right_top\"])::before,:host([current-position=\"left_top\"])::before{top:var(--arrow-edge-offset)}:host([current-position=\"right_top\"])::before,:host([current-position=\"right_bottom\"])::before{right:var(--arrow-center-y-offset)}:host([current-position=\"left_top\"])::before,:host([current-position=\"left_bottom\"])::before{left:var(--arrow-center-y-offset)}:host([current-position=\"right_bottom\"])::before,:host([current-position=\"left_bottom\"])::before{bottom:var(--arrow-edge-offset)}:host([center][current-position=\"top\"])::before,:host([center][current-position=\"bottom\"])::before{right:auto;left:var(--arrow-center-x-offset)}:host([center][current-position=\"right\"])::before,:host([center][current-position=\"left\"])::before{top:var(--arrow-center-x-offset);bottom:auto}";
5
7
  const ZPopoverStyle0 = stylesCss;
6
8
 
7
- const DOCUMENT_ELEMENT = document.documentElement;
8
- function getParentElement(element) {
9
- if (element.parentNode === element.shadowRoot) {
10
- return element.shadowRoot.host;
11
- }
12
- return element.parentElement;
13
- }
14
- /**
15
- * Find the closest scrollable parent of a node.
16
- *
17
- * @param {Element} element The node
18
- */
19
- function findScrollableParent(element) {
20
- let parent = getParentElement(element);
21
- while (parent && parent !== DOCUMENT_ELEMENT) {
22
- const style = window.getComputedStyle(parent);
23
- const { overflow, overflowX, overflowY } = style;
24
- // Check for hidden overflow first (early return)
25
- if (overflow === "hidden" || overflowY === "hidden" || overflowX === "hidden") {
26
- return parent;
27
- }
28
- // Only check scrollable if overflow is not visible
29
- const isOverflowNotVisible = overflow !== "visible";
30
- const isOverflowYNotVisible = overflowY !== "visible";
31
- const isOverflowXNotVisible = overflowX !== "visible";
32
- if ((parent.scrollHeight > parent.clientHeight && isOverflowNotVisible && isOverflowYNotVisible) ||
33
- (parent.scrollWidth > parent.clientWidth && isOverflowNotVisible && isOverflowXNotVisible)) {
34
- return parent;
35
- }
36
- parent = getParentElement(parent);
37
- }
38
- return DOCUMENT_ELEMENT;
39
- }
40
- /**
41
- * Calculate computed offset.
42
- * It includes matrix transformations.
43
- * @param element The target element.
44
- * @param targetParentOffset The relative offset parent.
45
- */
46
- function computeOffset(element, targetParentOffset) {
47
- const rect = element.getBoundingClientRect();
48
- const { width, height } = rect;
49
- let top = 0;
50
- let left = 0;
51
- let offsetParent = element;
52
- while (offsetParent && offsetParent !== targetParentOffset) {
53
- left += offsetParent.offsetLeft;
54
- // document.body sometimes has offsetTop == 0 but still has an offset because of children margins!
55
- if (offsetParent === document.body) {
56
- top += offsetParent.getBoundingClientRect().top + window.scrollY;
57
- }
58
- else {
59
- top += offsetParent.offsetTop;
60
- }
61
- // Handle CSS transforms only when DOMMatrix is available
62
- if (window.DOMMatrix) {
63
- const style = window.getComputedStyle(offsetParent);
64
- const { transform } = style;
65
- if (transform && transform !== "none") {
66
- const domMatrix = new DOMMatrix(transform);
67
- left += domMatrix.m41;
68
- if (offsetParent !== document.body) {
69
- top += domMatrix.m42;
70
- }
71
- }
72
- }
73
- if (!offsetParent.offsetParent) {
74
- break;
75
- }
76
- offsetParent = offsetParent.offsetParent;
77
- }
78
- let parentWidth;
79
- let parentHeight;
80
- if (offsetParent === document.body) {
81
- parentWidth = window.innerWidth;
82
- parentHeight = window.innerHeight;
83
- }
84
- else {
85
- parentWidth = offsetParent.offsetWidth;
86
- parentHeight = offsetParent.offsetHeight;
87
- }
88
- const right = parentWidth - left - width;
89
- const bottom = parentHeight - top - height;
90
- return { top, right, bottom, left, width, height };
91
- }
92
9
  const ZPopover = class {
93
10
  constructor(hostRef) {
94
11
  registerInstance(this, hostRef);
95
12
  this.positionChange = createEvent(this, "positionChange", 7);
96
13
  this.openChange = createEvent(this, "openChange", 7);
97
- this.spaceTolerance = 3; // 3px tolerance for space calculations
14
+ /** space tolerance for space calculations */
15
+ this.spaceTolerance = 3;
98
16
  this.position = PopoverPosition.TOP;
99
17
  this.open = false;
100
18
  this.bindTo = undefined;
@@ -112,71 +30,97 @@ const ZPopover = class {
112
30
  * Close the popover when clicking outside of its content.
113
31
  * Stop event propagation if the click was fired by popover's trigger element,
114
32
  * to prevent close and reopen glitches.
115
- * @param {MouseEvent} e
116
33
  */
117
34
  handleOutsideClick(e) {
118
- if (!this.closable || !this.open) {
35
+ const target = e.target;
36
+ if (!this.closable || !this.open || containsElement(this.host, target)) {
119
37
  return;
120
38
  }
121
- const eventPath = e.composedPath();
122
- if (!eventPath.includes(this.host)) {
123
- const target = e.target;
124
- let triggerElemClicked = false;
125
- if (typeof this.bindTo === "string") {
126
- triggerElemClicked = !!target.closest(this.bindTo);
127
- }
128
- else if (this.bindTo) {
129
- triggerElemClicked = this.bindTo.contains(target);
130
- }
131
- if (triggerElemClicked) {
132
- // stop propagation if the click was on the trigger element to prevent close and reopen glitches
133
- e.stopPropagation();
134
- }
135
- this.open = false;
136
- this.positionChange.emit({ position: this.currentPosition });
39
+ if (containsElement(this.boundElement, target)) {
40
+ // stop propagation if the click was on the trigger element to prevent close and reopen glitches
41
+ e.stopPropagation();
137
42
  }
43
+ this.open = false;
138
44
  }
139
45
  validatePosition(newValue) {
140
46
  if (!Object.values(PopoverPosition).includes(newValue) || newValue === PopoverPosition.AUTO) {
141
47
  newValue = PopoverPosition.TOP;
48
+ this.position = newValue;
142
49
  }
143
- this.position = newValue;
144
50
  this.currentPosition = newValue;
145
- this.positionChange.emit({ position: this.currentPosition });
146
- this.setPosition();
51
+ if (this.open) {
52
+ this.setPosition();
53
+ }
147
54
  }
148
- /**
149
- * Setup popover behaviors on opening.
150
- */
55
+ /** Setup popover behaviors when `open` changes. */
151
56
  onOpen() {
152
57
  cancelAnimationFrame(this.animationFrameRequestId);
153
- if (this.open) {
154
- const setPosition = () => {
155
- if (this.open) {
156
- this.setPosition();
157
- this.animationFrameRequestId = requestAnimationFrame(setPosition);
158
- }
159
- };
160
- // call `setPosition` after a tick to ensure the DOM is ready and sizes are available
161
- setTimeout(() => {
162
- setPosition();
163
- }, 0);
164
- }
165
58
  this.openChange.emit({ open: this.open });
59
+ if (!this.open) {
60
+ return;
61
+ }
62
+ const updatePositionLoop = () => {
63
+ if (!this.open) {
64
+ return;
65
+ }
66
+ this.setPosition();
67
+ this.animationFrameRequestId = requestAnimationFrame(updatePositionLoop);
68
+ };
69
+ // call `setPosition` after a tick to ensure the DOM is ready and sizes are available
70
+ setTimeout(() => {
71
+ updatePositionLoop();
72
+ }, 0);
73
+ }
74
+ onBindingChange() {
75
+ this.findBoundElement();
76
+ }
77
+ /** Returns the offset modifier to use in calculations to align the popover with the bound element. */
78
+ get offsetModifier() {
79
+ return this.center ? 0.5 : 0;
80
+ }
81
+ findBoundElement() {
82
+ if (typeof this.bindTo === "string") {
83
+ this.boundElement = this.host.ownerDocument.querySelector(this.bindTo);
84
+ }
85
+ else if (this.bindTo) {
86
+ this.boundElement = this.bindTo;
87
+ }
88
+ else {
89
+ this.boundElement = this.host.parentElement;
90
+ }
166
91
  }
167
92
  /**
168
- * Helper functions for space calculation
93
+ * Check if element has enough space to the right and left to be centered.
94
+ * Used for `TOP` and `BOTTOM` position.
95
+ * When `center` is not enabled, only one side needs to be checked and `RIGHT` is the default.
169
96
  */
170
- hasCenteredHorizontalSpace(availableLeft, availableRight, hostWidth, boundWidth, offsetModifier) {
171
- const requiredSpace = (hostWidth - boundWidth) * (1 - offsetModifier);
172
- return (availableLeft >= requiredSpace - this.spaceTolerance && availableRight >= requiredSpace - this.spaceTolerance);
97
+ hasCenteredHorizontalSpace(availableLeft, availableRight, hostWidth, boundElementWidth) {
98
+ const requiredSideSpace = (hostWidth - boundElementWidth) * (1 - this.offsetModifier);
99
+ if (!this.center) {
100
+ return availableRight >= requiredSideSpace - this.spaceTolerance;
101
+ }
102
+ return (availableRight >= requiredSideSpace - this.spaceTolerance &&
103
+ availableLeft >= requiredSideSpace - this.spaceTolerance);
173
104
  }
174
- hasCenteredVerticalSpace(availableTop, availableBottom, hostHeight, boundHeight, offsetModifier) {
175
- const requiredSpace = (hostHeight - boundHeight) * (1 - offsetModifier);
176
- return (availableTop >= requiredSpace - this.spaceTolerance && availableBottom >= requiredSpace - this.spaceTolerance);
105
+ /**
106
+ * Check if element has enough space to the top and bottom to be centered.
107
+ * Used for `RIGHT` and `LEFT` position.
108
+ * When `center` is not enabled, only one side needs to be checked and `BOTTOM` is the default.
109
+ */
110
+ hasCenteredVerticalSpace(availableTop, availableBottom, hostHeight, boundElementHeight) {
111
+ const requiredSideSpace = (hostHeight - boundElementHeight) * (1 - this.offsetModifier);
112
+ if (!this.center) {
113
+ return availableBottom >= requiredSideSpace - this.spaceTolerance;
114
+ }
115
+ return (availableTop >= requiredSideSpace - this.spaceTolerance &&
116
+ availableBottom >= requiredSideSpace - this.spaceTolerance);
177
117
  }
178
- hasOffsetSpace(availableSpace, hostSize, boundSize, offsetModifier) {
179
- return availableSpace >= hostSize - boundSize * (1 - offsetModifier) - this.spaceTolerance;
118
+ /**
119
+ * Check if there is enough space in the given direction to fit the popover.
120
+ * Used for composed positions like TOP_RIGHT, LEFT_BOTTOM, etc.
121
+ */
122
+ hasEnoughSideSpace(availableSpace, hostSize, boundElementSize, offsetModifier) {
123
+ return availableSpace >= hostSize - boundElementSize * (1 - offsetModifier) - this.spaceTolerance;
180
124
  }
181
125
  /**
182
126
  * Given a desired position and available space around the bound element, returns the best position
@@ -184,51 +128,52 @@ const ZPopover = class {
184
128
  * Takes into account offsetModifier for centering.
185
129
  * @param desiredPosition The desired position of the popover.
186
130
  * @param availableSpace The available space around the bound element.
187
- * @param boundElemSizes The sizes of the bound element.
188
- * @param offsetModifier The modifier to apply to the offset for centering.
189
131
  */
190
- getOptimalPopoverPosition(desiredPosition, availableSpace, boundElemSizes, offsetModifier) {
132
+ getOptimalPopoverPosition(desiredPosition, availableSpace) {
191
133
  const hostWidth = this.host.offsetWidth;
192
134
  const hostHeight = this.host.offsetHeight;
193
- // Check if the desired position has enough space
135
+ const boundElementWidth = this.boundElement.getBoundingClientRect().width;
136
+ const boundElementHeight = this.boundElement.getBoundingClientRect().height;
137
+ const offsetModifier = this.offsetModifier;
138
+ /** Check if there is enough space to fit the popover in the desired position */
194
139
  const fits = (pos) => {
195
140
  switch (pos) {
196
141
  case PopoverPosition.TOP:
197
- return (availableSpace.top >= hostHeight &&
198
- this.hasCenteredHorizontalSpace(availableSpace.left, availableSpace.right, hostWidth, boundElemSizes.width, offsetModifier));
142
+ return (availableSpace.top >= hostHeight - this.spaceTolerance &&
143
+ this.hasCenteredHorizontalSpace(availableSpace.left, availableSpace.right, hostWidth, boundElementWidth));
199
144
  case PopoverPosition.TOP_RIGHT:
200
145
  return (availableSpace.top >= hostHeight &&
201
- this.hasOffsetSpace(availableSpace.right, hostWidth, boundElemSizes.width, offsetModifier));
146
+ this.hasEnoughSideSpace(availableSpace.right, hostWidth, boundElementWidth, offsetModifier));
202
147
  case PopoverPosition.TOP_LEFT:
203
148
  return (availableSpace.top >= hostHeight &&
204
- this.hasOffsetSpace(availableSpace.left, hostWidth, boundElemSizes.width, offsetModifier));
149
+ this.hasEnoughSideSpace(availableSpace.left, hostWidth, boundElementWidth, offsetModifier));
205
150
  case PopoverPosition.RIGHT:
206
151
  return (availableSpace.right >= hostWidth &&
207
- this.hasCenteredVerticalSpace(availableSpace.top, availableSpace.bottom, hostHeight, boundElemSizes.height, offsetModifier));
152
+ this.hasCenteredVerticalSpace(availableSpace.top, availableSpace.bottom, hostHeight, boundElementHeight));
208
153
  case PopoverPosition.RIGHT_BOTTOM:
209
154
  return (availableSpace.right >= hostWidth &&
210
- this.hasOffsetSpace(availableSpace.bottom, hostHeight, boundElemSizes.height, offsetModifier));
155
+ this.hasEnoughSideSpace(availableSpace.bottom, hostHeight, boundElementHeight, offsetModifier));
211
156
  case PopoverPosition.RIGHT_TOP:
212
157
  return (availableSpace.right >= hostWidth &&
213
- this.hasOffsetSpace(availableSpace.top, hostHeight, boundElemSizes.height, offsetModifier));
158
+ this.hasEnoughSideSpace(availableSpace.top, hostHeight, boundElementHeight, offsetModifier));
214
159
  case PopoverPosition.BOTTOM:
215
160
  return (availableSpace.bottom >= hostHeight &&
216
- this.hasCenteredHorizontalSpace(availableSpace.left, availableSpace.right, hostWidth, boundElemSizes.width, offsetModifier));
161
+ this.hasCenteredHorizontalSpace(availableSpace.left, availableSpace.right, hostWidth, boundElementWidth));
217
162
  case PopoverPosition.BOTTOM_LEFT:
218
163
  return (availableSpace.bottom >= hostHeight &&
219
- this.hasOffsetSpace(availableSpace.left, hostWidth, boundElemSizes.width, offsetModifier));
164
+ this.hasEnoughSideSpace(availableSpace.left, hostWidth, boundElementWidth, offsetModifier));
220
165
  case PopoverPosition.BOTTOM_RIGHT:
221
166
  return (availableSpace.bottom >= hostHeight &&
222
- this.hasOffsetSpace(availableSpace.right, hostWidth, boundElemSizes.width, offsetModifier));
167
+ this.hasEnoughSideSpace(availableSpace.right, hostWidth, boundElementWidth, offsetModifier));
223
168
  case PopoverPosition.LEFT:
224
169
  return (availableSpace.left >= hostWidth &&
225
- this.hasCenteredVerticalSpace(availableSpace.top, availableSpace.bottom, hostHeight, boundElemSizes.height, offsetModifier));
170
+ this.hasCenteredVerticalSpace(availableSpace.top, availableSpace.bottom, hostHeight, boundElementHeight));
226
171
  case PopoverPosition.LEFT_TOP:
227
172
  return (availableSpace.left >= hostWidth &&
228
- this.hasOffsetSpace(availableSpace.top, hostHeight, boundElemSizes.height, offsetModifier));
173
+ this.hasEnoughSideSpace(availableSpace.top, hostHeight, boundElementHeight, offsetModifier));
229
174
  case PopoverPosition.LEFT_BOTTOM:
230
175
  return (availableSpace.left >= hostWidth &&
231
- this.hasOffsetSpace(availableSpace.bottom, hostHeight, boundElemSizes.height, offsetModifier));
176
+ this.hasEnoughSideSpace(availableSpace.bottom, hostHeight, boundElementHeight, offsetModifier));
232
177
  default:
233
178
  return false;
234
179
  }
@@ -254,27 +199,25 @@ const ZPopover = class {
254
199
  // If no position fits, find the best fallback based on available space
255
200
  return this.findBestFallbackPosition(availableSpace);
256
201
  }
257
- /**
258
- * Find the best fallback position based on available space when no position fits perfectly
259
- */
202
+ /** Find the best fallback position based on available space when no position fits perfectly. */
260
203
  findBestFallbackPosition(availableSpace) {
261
- // Determine the directions with the most space
204
+ // Determine which horizontal and vertical direction has the most available space
262
205
  const bestHorizontalDirection = availableSpace.right >= availableSpace.left ? PopoverPosition.RIGHT : PopoverPosition.LEFT;
263
206
  const bestVerticalDirection = availableSpace.bottom >= availableSpace.top ? PopoverPosition.BOTTOM : PopoverPosition.TOP;
264
- // Choose the main direction based on which has more space
207
+ // Choose the main direction based on which axis has more space overall
265
208
  const maxHorizontalSpace = Math.max(availableSpace.right, availableSpace.left);
266
209
  const maxVerticalSpace = Math.max(availableSpace.bottom, availableSpace.top);
267
210
  const mainDirection = maxVerticalSpace >= maxHorizontalSpace ? bestVerticalDirection : bestHorizontalDirection;
268
- // Check if secondary direction is necessary
269
- // Only add secondary direction if the difference between min and max in that direction is at least double
211
+ // Decide if a secondary direction is needed
212
+ // Only add a secondary direction if the difference between min and max in that axis is at least double
270
213
  let needsSecondaryDirection = false;
271
214
  if (mainDirection === bestVerticalDirection) {
272
- // Main direction is vertical, check horizontal space difference
215
+ // If main direction is vertical, check horizontal space difference
273
216
  const minHorizontalSpace = Math.min(availableSpace.right, availableSpace.left);
274
217
  needsSecondaryDirection = maxHorizontalSpace >= minHorizontalSpace * 2;
275
218
  }
276
219
  else {
277
- // Main direction is horizontal, check vertical space difference
220
+ // If main direction is horizontal, check vertical space difference
278
221
  const minVerticalSpace = Math.min(availableSpace.bottom, availableSpace.top);
279
222
  needsSecondaryDirection = maxVerticalSpace >= minVerticalSpace * 2;
280
223
  }
@@ -282,184 +225,209 @@ const ZPopover = class {
282
225
  return mainDirection;
283
226
  }
284
227
  const secondaryDirection = mainDirection === bestVerticalDirection ? bestHorizontalDirection : bestVerticalDirection;
285
- // Create a combined position (e.g., "bottom_right")
228
+ // Return a combined position (e.g., "bottom_right")
286
229
  return `${mainDirection}_${secondaryDirection}`;
287
230
  }
288
231
  /**
289
- * Calculate available space around the bound element
232
+ * Calculate available space around the element bound with the popover, based on its nearest scrollable ancestor.
233
+ *
234
+ * Calculations for `right` and `bottom` can be a little bit confusing because `boundingRect.right` and `bottom` may not be what you expect...
235
+ * For more information see the explanation in the docs.
236
+ * @link https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect#return_value
290
237
  */
291
- calculateAvailableSpace(boundElementRect, scrollContainer, scrollingBoundingRect) {
292
- const top = boundElementRect.top - scrollContainer.scrollTop;
293
- const bottom = scrollingBoundingRect.height - (boundElementRect.top + boundElementRect.height) + scrollContainer.scrollTop;
294
- const left = boundElementRect.left - scrollContainer.scrollLeft;
295
- const right = scrollingBoundingRect.width - (boundElementRect.left + boundElementRect.width) + scrollContainer.scrollLeft;
296
- const overflowBottom = Math.max(0, scrollingBoundingRect.top + scrollingBoundingRect.height - window.innerHeight);
297
- const overflowRight = Math.max(0, scrollingBoundingRect.left + scrollingBoundingRect.width - window.innerWidth);
298
- return {
299
- top: Math.min(top, top + scrollingBoundingRect.top),
300
- bottom: Math.min(bottom, bottom - overflowBottom),
301
- left: Math.min(left, left + scrollingBoundingRect.left),
302
- right: Math.min(right, right - overflowRight),
238
+ calculateAvailableSpace() {
239
+ const boundElementRect = this.boundElement.getBoundingClientRect();
240
+ if (this.lastBoundRect &&
241
+ this.lastBoundRect.x === boundElementRect.x &&
242
+ this.lastBoundRect.y === boundElementRect.y &&
243
+ this.lastBoundRect.width === boundElementRect.width &&
244
+ this.lastBoundRect.height === boundElementRect.height &&
245
+ this.cachedAvailableSpace) {
246
+ // If the bound element's rect hasn't changed, return the cached rect
247
+ return this.cachedAvailableSpace;
248
+ }
249
+ this.lastBoundRect = boundElementRect;
250
+ const scrollableParent = findScrollableParent(this.boundElement);
251
+ const scrollableParentRect = scrollableParent.getBoundingClientRect();
252
+ const hasNestedScrollableParent = scrollableParent !== this.boundElement.ownerDocument.documentElement;
253
+ const documentWidth = this.boundElement.ownerDocument.documentElement.clientWidth;
254
+ const documentHeight = this.boundElement.ownerDocument.documentElement.clientHeight;
255
+ const safeSpace = 8; // extra space to avoid popover being too close to the edges
256
+ // These deltas represent the offset between the scrollable parent and the viewport.
257
+ // They are used to adjust the available space calculations when the scrollable parent is not the document or body,
258
+ // to try to fit the popover inside the scrollable parent.
259
+ const deltaTop = hasNestedScrollableParent ? scrollableParentRect.top : 0;
260
+ const deltaRight = hasNestedScrollableParent ? documentWidth - scrollableParentRect.right : 0;
261
+ const deltaBottom = hasNestedScrollableParent ? documentHeight - scrollableParentRect.bottom : 0;
262
+ const deltaLeft = hasNestedScrollableParent ? scrollableParentRect.left : 0;
263
+ this.cachedAvailableSpace = {
264
+ top: boundElementRect.top - deltaTop - safeSpace,
265
+ right: documentWidth - boundElementRect.right - deltaRight - safeSpace,
266
+ bottom: documentHeight - boundElementRect.bottom - deltaBottom - safeSpace,
267
+ left: boundElementRect.left - deltaLeft - safeSpace,
303
268
  };
269
+ return this.cachedAvailableSpace;
304
270
  }
305
- /**
306
- * Calculate relative offsets for positioning
307
- */
308
- calculateRelativeOffsets(boundElementRect, relativeBoundingRect) {
271
+ /** Calculate the space around an element relative to the viewport. */
272
+ calculateElementOffsets(element) {
273
+ const elementRect = element.getBoundingClientRect();
274
+ const viewportWidth = element.ownerDocument.documentElement.clientWidth;
275
+ const viewportHeight = element.ownerDocument.documentElement.clientHeight;
309
276
  return {
310
- top: boundElementRect.top - relativeBoundingRect.top,
311
- right: boundElementRect.right - relativeBoundingRect.right,
312
- bottom: boundElementRect.bottom - relativeBoundingRect.bottom,
313
- left: boundElementRect.left - relativeBoundingRect.left,
277
+ top: elementRect.top,
278
+ right: viewportWidth - elementRect.right,
279
+ bottom: viewportHeight - elementRect.bottom,
280
+ left: elementRect.left,
314
281
  };
315
282
  }
316
- /**
317
- * Apply positioning styles based on position
318
- */
319
- applyPositionStyles(position, style, offsets, boundElementSizes, availableSpace, offsetModifier, arrowModifier) {
320
- const distanceFromBound = 8; // 8px is the distance of the popover from the bound element
321
- // Reset all positioning properties
322
- style.top = "auto";
323
- style.right = "auto";
324
- style.bottom = "auto";
325
- style.left = "auto";
326
- style.maxWidth = "";
327
- style.maxHeight = "";
283
+ /** Apply positioning styles based on passed position. */
284
+ applyPositionStyles(position, availableSpace) {
285
+ const boundElementWidth = this.boundElement.offsetWidth;
286
+ const boundElementHeight = this.boundElement.offsetHeight;
287
+ /** Distance between the popover and the bound element */
288
+ const distanceFromBound = 8;
289
+ const offsetModifier = this.offsetModifier;
290
+ /** Distance between the arrow center and the popover edge. Needed to align the center of the arrow with the center of the bound element when `showArrow` and `center` are enabled. */
291
+ const arrowModifier = this.showArrow && this.center ? 8 : 0;
292
+ const hostStyle = this.host.style;
293
+ const boundElementOffsets = this.calculateElementOffsets(this.boundElement);
294
+ let maxWidth;
295
+ let maxHeight;
328
296
  switch (position) {
329
297
  case PopoverPosition.TOP:
330
298
  case PopoverPosition.TOP_RIGHT:
331
- style.bottom = `${offsets.bottom + boundElementSizes.height}px`;
332
- style.left = `${offsets.left + boundElementSizes.width * offsetModifier - (position === PopoverPosition.TOP_RIGHT ? arrowModifier : 0)}px`;
333
- style.maxHeight = `${availableSpace.top - distanceFromBound}px`;
299
+ hostStyle.bottom = `${boundElementOffsets.bottom + boundElementHeight}px`;
300
+ hostStyle.left = `${boundElementOffsets.left + boundElementWidth * offsetModifier - (position === PopoverPosition.TOP_RIGHT ? arrowModifier : 0)}px`;
301
+ maxHeight = availableSpace.top - distanceFromBound;
334
302
  if (position === PopoverPosition.TOP_RIGHT) {
335
- style.maxWidth = `${availableSpace.right + boundElementSizes.width * offsetModifier}px`;
303
+ maxWidth = availableSpace.right + boundElementWidth * offsetModifier;
336
304
  }
337
305
  break;
338
306
  case PopoverPosition.TOP_LEFT:
339
- style.right = `${offsets.right + boundElementSizes.width * offsetModifier - arrowModifier}px`;
340
- style.bottom = `${offsets.bottom + boundElementSizes.height}px`;
341
- style.maxWidth = `${availableSpace.left}px`;
342
- style.maxHeight = `${availableSpace.top - distanceFromBound}px`;
307
+ hostStyle.right = `${boundElementOffsets.right + boundElementWidth * offsetModifier - arrowModifier}px`;
308
+ hostStyle.bottom = `${boundElementOffsets.bottom + boundElementHeight}px`;
309
+ maxWidth = availableSpace.left + boundElementWidth * offsetModifier;
310
+ maxHeight = availableSpace.top - distanceFromBound;
343
311
  break;
344
312
  case PopoverPosition.BOTTOM:
345
313
  case PopoverPosition.BOTTOM_RIGHT:
346
- style.top = `${offsets.top + boundElementSizes.height}px`;
347
- style.left = `${offsets.left + boundElementSizes.width * offsetModifier - (position === PopoverPosition.BOTTOM_RIGHT ? arrowModifier : 0)}px`;
348
- style.maxHeight = `${availableSpace.bottom - distanceFromBound}px`;
314
+ hostStyle.top = `${boundElementOffsets.top + boundElementHeight}px`;
315
+ hostStyle.left = `${boundElementOffsets.left + boundElementWidth * offsetModifier - (position === PopoverPosition.BOTTOM_RIGHT ? arrowModifier : 0)}px`;
316
+ maxHeight = availableSpace.bottom - distanceFromBound;
349
317
  if (position === PopoverPosition.BOTTOM_RIGHT) {
350
- style.maxWidth = `${availableSpace.right + boundElementSizes.width * offsetModifier}px`;
318
+ maxWidth = availableSpace.right + boundElementWidth * offsetModifier;
351
319
  }
352
320
  break;
353
321
  case PopoverPosition.BOTTOM_LEFT:
354
- style.top = `${offsets.top + boundElementSizes.height}px`;
355
- style.right = `${offsets.right + boundElementSizes.width * offsetModifier - arrowModifier}px`;
356
- style.maxWidth = `${availableSpace.left}px`;
357
- style.maxHeight = `${availableSpace.bottom - distanceFromBound}px`;
322
+ hostStyle.top = `${boundElementOffsets.top + boundElementHeight}px`;
323
+ hostStyle.right = `${boundElementOffsets.right + boundElementWidth * offsetModifier - arrowModifier}px`;
324
+ maxWidth = availableSpace.left + boundElementWidth * offsetModifier;
325
+ maxHeight = availableSpace.bottom - distanceFromBound;
358
326
  break;
359
327
  case PopoverPosition.RIGHT:
360
328
  case PopoverPosition.RIGHT_BOTTOM:
361
- style.top = `${offsets.top + boundElementSizes.height * offsetModifier - (position === PopoverPosition.RIGHT_BOTTOM ? arrowModifier : 0)}px`;
362
- style.left = `${offsets.left + boundElementSizes.width}px`;
363
- style.maxWidth = `${availableSpace.right - distanceFromBound}px`;
329
+ hostStyle.top = `${boundElementOffsets.top + boundElementHeight * offsetModifier - (position === PopoverPosition.RIGHT_BOTTOM ? arrowModifier : 0)}px`;
330
+ hostStyle.left = `${boundElementOffsets.left + boundElementWidth}px`;
331
+ maxWidth = availableSpace.right - distanceFromBound;
364
332
  if (position === PopoverPosition.RIGHT) {
365
- style.maxHeight = `${Math.min(availableSpace.top + availableSpace.bottom + boundElementSizes.height, window.innerHeight - 20)}px`;
333
+ maxHeight = availableSpace.top + availableSpace.bottom + boundElementHeight;
366
334
  }
367
335
  else {
368
- style.maxHeight = `${availableSpace.bottom + boundElementSizes.height * offsetModifier}px`;
336
+ maxHeight = availableSpace.bottom + boundElementHeight * offsetModifier;
369
337
  }
370
338
  break;
371
339
  case PopoverPosition.RIGHT_TOP:
372
- style.bottom = `${offsets.bottom + boundElementSizes.height * offsetModifier - arrowModifier}px`;
373
- style.left = `${offsets.left + boundElementSizes.width}px`;
374
- style.maxWidth = `${availableSpace.right - distanceFromBound}px`;
375
- if (position === PopoverPosition.RIGHT_TOP) {
376
- style.maxHeight = `${availableSpace.top + boundElementSizes.height * offsetModifier}px`;
377
- }
340
+ hostStyle.bottom = `${boundElementOffsets.bottom + boundElementHeight * offsetModifier - arrowModifier}px`;
341
+ hostStyle.left = `${boundElementOffsets.left + boundElementWidth}px`;
342
+ maxWidth = availableSpace.right - distanceFromBound;
343
+ maxHeight = availableSpace.top + boundElementHeight * offsetModifier;
378
344
  break;
379
345
  case PopoverPosition.LEFT:
380
346
  case PopoverPosition.LEFT_BOTTOM:
381
- style.top = `${offsets.top + boundElementSizes.height * offsetModifier - (position === PopoverPosition.LEFT_BOTTOM ? arrowModifier : 0)}px`;
382
- style.right = `${offsets.right + boundElementSizes.width}px`;
383
- style.maxWidth = `${availableSpace.left - distanceFromBound}px`;
347
+ hostStyle.top = `${boundElementOffsets.top + boundElementHeight * offsetModifier - (position === PopoverPosition.LEFT_BOTTOM ? arrowModifier : 0)}px`;
348
+ hostStyle.right = `${boundElementOffsets.right + boundElementWidth}px`;
349
+ maxWidth = availableSpace.left - distanceFromBound;
384
350
  if (position === PopoverPosition.LEFT_BOTTOM) {
385
- style.maxHeight = `${availableSpace.bottom + boundElementSizes.height * offsetModifier}px`;
351
+ maxHeight = availableSpace.bottom + boundElementHeight * offsetModifier;
386
352
  }
387
353
  break;
388
354
  case PopoverPosition.LEFT_TOP:
389
- style.right = `${offsets.right + boundElementSizes.width}px`;
390
- style.bottom = `${offsets.bottom + boundElementSizes.height * offsetModifier - arrowModifier}px`;
391
- style.maxWidth = `${availableSpace.left - distanceFromBound}px`;
392
- if (position === PopoverPosition.LEFT_TOP) {
393
- style.maxHeight = `${availableSpace.top + boundElementSizes.height * offsetModifier}px`;
394
- }
355
+ hostStyle.right = `${boundElementOffsets.right + boundElementWidth}px`;
356
+ hostStyle.bottom = `${boundElementOffsets.bottom + boundElementHeight * offsetModifier - arrowModifier}px`;
357
+ maxWidth = availableSpace.left - distanceFromBound;
358
+ maxHeight = availableSpace.top + boundElementHeight * offsetModifier;
395
359
  break;
396
360
  }
361
+ if (getDevice() !== Device.MOBILE) {
362
+ // Only force max sizes on non-mobile viewports
363
+ hostStyle.maxWidth = maxWidth ? `${maxWidth}px` : "";
364
+ hostStyle.maxHeight = maxHeight ? `${maxHeight}px` : "";
365
+ }
397
366
  }
398
- /**
399
- * Set the position of the popover.
400
- */
367
+ /** Set the position of the popover. */
401
368
  setPosition() {
402
- let boundElement;
403
- if (typeof this.bindTo === "string") {
404
- boundElement = this.host.ownerDocument.querySelector(this.bindTo);
405
- }
406
- else if (this.bindTo) {
407
- boundElement = this.bindTo;
408
- }
409
- else {
410
- boundElement = this.host.parentElement;
369
+ if (!this.boundElement) {
370
+ return;
411
371
  }
412
- if (!boundElement) {
372
+ if (!isElementVisibleInContainer(this.boundElement, findScrollableParent(this.boundElement))) {
373
+ // If the bound element is not visible, hide the popover too
374
+ this.open = false;
413
375
  return;
414
376
  }
415
- const scrollContainer = findScrollableParent(boundElement);
416
- const scrollingBoundingRect = scrollContainer.getBoundingClientRect();
417
- const offsetContainer = this.host.offsetParent;
418
- const relativeBoundingRect = offsetContainer
419
- ? computeOffset(offsetContainer, scrollContainer)
420
- : { top: 0, right: 0, bottom: 0, left: 0 };
421
- const boundElementRect = computeOffset(boundElement, scrollContainer);
422
- const availableSpace = this.calculateAvailableSpace(boundElementRect, scrollContainer, scrollingBoundingRect);
423
- const offsets = this.calculateRelativeOffsets(boundElementRect, relativeBoundingRect);
424
- const offsetModifier = this.center ? 0.5 : 0;
425
- const arrowModifier = this.showArrow && this.center ? 8 : 0; // 8px is the distance of the arrow center from the edge of the popover
426
- const position = this.getOptimalPopoverPosition(this.position, availableSpace, { width: boundElementRect.width, height: boundElementRect.height }, offsetModifier);
427
- const style = this.host.style;
428
- this.applyPositionStyles(position, style, offsets, boundElementRect, availableSpace, offsetModifier, arrowModifier);
377
+ Object.assign(this.host.style, {
378
+ // Reset all positioning properties
379
+ top: "auto",
380
+ right: "auto",
381
+ bottom: "auto",
382
+ left: "auto",
383
+ maxWidth: "",
384
+ maxHeight: "",
385
+ // Set initial visibility to hidden while calculating position...
386
+ visibility: "hidden",
387
+ });
388
+ const availableSpace = this.calculateAvailableSpace();
389
+ const position = this.getOptimalPopoverPosition(this.position, availableSpace);
390
+ this.applyPositionStyles(position, availableSpace);
429
391
  this.currentPosition = position;
392
+ this.positionChange.emit({ position: this.currentPosition });
393
+ // ...then restore the visibility
394
+ this.host.style.visibility = "visible";
430
395
  }
431
396
  componentWillLoad() {
432
397
  this.validatePosition(this.position);
433
- this.onOpen();
434
398
  }
435
399
  componentDidLoad() {
436
- this.setPosition();
400
+ this.findBoundElement();
401
+ if (this.open) {
402
+ this.onOpen();
403
+ }
437
404
  }
438
405
  disconnectedCallback() {
439
406
  cancelAnimationFrame(this.animationFrameRequestId);
440
407
  }
441
408
  render() {
442
- return (h(Host, { key: '8628b0f299deb808e4c554047c76b82f392782c9', "current-position": this.currentPosition }, h("slot", { key: '144294e8216d7ad673e4ee3a96651c053703d135' })));
409
+ return (h(Host, { key: '1eafd1bd08aa31a81378354542b0e74edc4cb0ce', "current-position": this.currentPosition }, h("slot", { key: '2ad916cf0e13766e2e5f92f4f964a4fe909cdc7a' })));
443
410
  }
444
411
  get host() { return getElement(this); }
445
412
  static get watchers() { return {
446
413
  "position": ["validatePosition"],
447
- "open": ["onOpen"]
414
+ "open": ["onOpen"],
415
+ "bindTo": ["onBindingChange"]
448
416
  }; }
449
417
  };
450
418
  // Clockwise order of positions.
451
419
  ZPopover.positionOrder = [
452
- PopoverPosition.TOP_RIGHT,
453
420
  PopoverPosition.TOP,
421
+ PopoverPosition.TOP_RIGHT,
454
422
  PopoverPosition.TOP_LEFT,
455
- PopoverPosition.RIGHT_BOTTOM,
456
423
  PopoverPosition.RIGHT,
424
+ PopoverPosition.RIGHT_BOTTOM,
457
425
  PopoverPosition.RIGHT_TOP,
458
- PopoverPosition.BOTTOM_LEFT,
459
426
  PopoverPosition.BOTTOM,
427
+ PopoverPosition.BOTTOM_LEFT,
460
428
  PopoverPosition.BOTTOM_RIGHT,
461
- PopoverPosition.LEFT_TOP,
462
429
  PopoverPosition.LEFT,
430
+ PopoverPosition.LEFT_TOP,
463
431
  PopoverPosition.LEFT_BOTTOM,
464
432
  ];
465
433
  ZPopover.style = ZPopoverStyle0;