@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,94 +1,10 @@
1
1
  import { proxyCustomElement, HTMLElement, createEvent, h, Host } from '@stencil/core/internal/client';
2
- import { P as PopoverPosition, g as KeyboardCode } from './index2.js';
2
+ import { P as PopoverPosition, g as KeyboardCode, p as Device } from './index2.js';
3
+ import { a as containsElement, i as findScrollableParent, g as getDevice, j as isElementVisibleInContainer } from './utils.js';
3
4
 
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}";
5
+ 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
6
  const ZPopoverStyle0 = stylesCss;
6
7
 
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
8
  const ZPopover = /*@__PURE__*/ proxyCustomElement(class ZPopover extends HTMLElement {
93
9
  constructor() {
94
10
  super();
@@ -96,7 +12,8 @@ const ZPopover = /*@__PURE__*/ proxyCustomElement(class ZPopover extends HTMLEle
96
12
  this.__attachShadow();
97
13
  this.positionChange = createEvent(this, "positionChange", 7);
98
14
  this.openChange = createEvent(this, "openChange", 7);
99
- this.spaceTolerance = 3; // 3px tolerance for space calculations
15
+ /** space tolerance for space calculations */
16
+ this.spaceTolerance = 3;
100
17
  this.position = PopoverPosition.TOP;
101
18
  this.open = false;
102
19
  this.bindTo = undefined;
@@ -114,71 +31,97 @@ const ZPopover = /*@__PURE__*/ proxyCustomElement(class ZPopover extends HTMLEle
114
31
  * Close the popover when clicking outside of its content.
115
32
  * Stop event propagation if the click was fired by popover's trigger element,
116
33
  * to prevent close and reopen glitches.
117
- * @param {MouseEvent} e
118
34
  */
119
35
  handleOutsideClick(e) {
120
- if (!this.closable || !this.open) {
36
+ const target = e.target;
37
+ if (!this.closable || !this.open || containsElement(this.host, target)) {
121
38
  return;
122
39
  }
123
- const eventPath = e.composedPath();
124
- if (!eventPath.includes(this.host)) {
125
- const target = e.target;
126
- let triggerElemClicked = false;
127
- if (typeof this.bindTo === "string") {
128
- triggerElemClicked = !!target.closest(this.bindTo);
129
- }
130
- else if (this.bindTo) {
131
- triggerElemClicked = this.bindTo.contains(target);
132
- }
133
- if (triggerElemClicked) {
134
- // stop propagation if the click was on the trigger element to prevent close and reopen glitches
135
- e.stopPropagation();
136
- }
137
- this.open = false;
138
- this.positionChange.emit({ position: this.currentPosition });
40
+ if (containsElement(this.boundElement, target)) {
41
+ // stop propagation if the click was on the trigger element to prevent close and reopen glitches
42
+ e.stopPropagation();
139
43
  }
44
+ this.open = false;
140
45
  }
141
46
  validatePosition(newValue) {
142
47
  if (!Object.values(PopoverPosition).includes(newValue) || newValue === PopoverPosition.AUTO) {
143
48
  newValue = PopoverPosition.TOP;
49
+ this.position = newValue;
144
50
  }
145
- this.position = newValue;
146
51
  this.currentPosition = newValue;
147
- this.positionChange.emit({ position: this.currentPosition });
148
- this.setPosition();
52
+ if (this.open) {
53
+ this.setPosition();
54
+ }
149
55
  }
150
- /**
151
- * Setup popover behaviors on opening.
152
- */
56
+ /** Setup popover behaviors when `open` changes. */
153
57
  onOpen() {
154
58
  cancelAnimationFrame(this.animationFrameRequestId);
155
- if (this.open) {
156
- const setPosition = () => {
157
- if (this.open) {
158
- this.setPosition();
159
- this.animationFrameRequestId = requestAnimationFrame(setPosition);
160
- }
161
- };
162
- // call `setPosition` after a tick to ensure the DOM is ready and sizes are available
163
- setTimeout(() => {
164
- setPosition();
165
- }, 0);
166
- }
167
59
  this.openChange.emit({ open: this.open });
60
+ if (!this.open) {
61
+ return;
62
+ }
63
+ const updatePositionLoop = () => {
64
+ if (!this.open) {
65
+ return;
66
+ }
67
+ this.setPosition();
68
+ this.animationFrameRequestId = requestAnimationFrame(updatePositionLoop);
69
+ };
70
+ // call `setPosition` after a tick to ensure the DOM is ready and sizes are available
71
+ setTimeout(() => {
72
+ updatePositionLoop();
73
+ }, 0);
74
+ }
75
+ onBindingChange() {
76
+ this.findBoundElement();
77
+ }
78
+ /** Returns the offset modifier to use in calculations to align the popover with the bound element. */
79
+ get offsetModifier() {
80
+ return this.center ? 0.5 : 0;
81
+ }
82
+ findBoundElement() {
83
+ if (typeof this.bindTo === "string") {
84
+ this.boundElement = this.host.ownerDocument.querySelector(this.bindTo);
85
+ }
86
+ else if (this.bindTo) {
87
+ this.boundElement = this.bindTo;
88
+ }
89
+ else {
90
+ this.boundElement = this.host.parentElement;
91
+ }
168
92
  }
169
93
  /**
170
- * Helper functions for space calculation
94
+ * Check if element has enough space to the right and left to be centered.
95
+ * Used for `TOP` and `BOTTOM` position.
96
+ * When `center` is not enabled, only one side needs to be checked and `RIGHT` is the default.
171
97
  */
172
- hasCenteredHorizontalSpace(availableLeft, availableRight, hostWidth, boundWidth, offsetModifier) {
173
- const requiredSpace = (hostWidth - boundWidth) * (1 - offsetModifier);
174
- return (availableLeft >= requiredSpace - this.spaceTolerance && availableRight >= requiredSpace - this.spaceTolerance);
98
+ hasCenteredHorizontalSpace(availableLeft, availableRight, hostWidth, boundElementWidth) {
99
+ const requiredSideSpace = (hostWidth - boundElementWidth) * (1 - this.offsetModifier);
100
+ if (!this.center) {
101
+ return availableRight >= requiredSideSpace - this.spaceTolerance;
102
+ }
103
+ return (availableRight >= requiredSideSpace - this.spaceTolerance &&
104
+ availableLeft >= requiredSideSpace - this.spaceTolerance);
175
105
  }
176
- hasCenteredVerticalSpace(availableTop, availableBottom, hostHeight, boundHeight, offsetModifier) {
177
- const requiredSpace = (hostHeight - boundHeight) * (1 - offsetModifier);
178
- return (availableTop >= requiredSpace - this.spaceTolerance && availableBottom >= requiredSpace - this.spaceTolerance);
106
+ /**
107
+ * Check if element has enough space to the top and bottom to be centered.
108
+ * Used for `RIGHT` and `LEFT` position.
109
+ * When `center` is not enabled, only one side needs to be checked and `BOTTOM` is the default.
110
+ */
111
+ hasCenteredVerticalSpace(availableTop, availableBottom, hostHeight, boundElementHeight) {
112
+ const requiredSideSpace = (hostHeight - boundElementHeight) * (1 - this.offsetModifier);
113
+ if (!this.center) {
114
+ return availableBottom >= requiredSideSpace - this.spaceTolerance;
115
+ }
116
+ return (availableTop >= requiredSideSpace - this.spaceTolerance &&
117
+ availableBottom >= requiredSideSpace - this.spaceTolerance);
179
118
  }
180
- hasOffsetSpace(availableSpace, hostSize, boundSize, offsetModifier) {
181
- return availableSpace >= hostSize - boundSize * (1 - offsetModifier) - this.spaceTolerance;
119
+ /**
120
+ * Check if there is enough space in the given direction to fit the popover.
121
+ * Used for composed positions like TOP_RIGHT, LEFT_BOTTOM, etc.
122
+ */
123
+ hasEnoughSideSpace(availableSpace, hostSize, boundElementSize, offsetModifier) {
124
+ return availableSpace >= hostSize - boundElementSize * (1 - offsetModifier) - this.spaceTolerance;
182
125
  }
183
126
  /**
184
127
  * Given a desired position and available space around the bound element, returns the best position
@@ -186,51 +129,52 @@ const ZPopover = /*@__PURE__*/ proxyCustomElement(class ZPopover extends HTMLEle
186
129
  * Takes into account offsetModifier for centering.
187
130
  * @param desiredPosition The desired position of the popover.
188
131
  * @param availableSpace The available space around the bound element.
189
- * @param boundElemSizes The sizes of the bound element.
190
- * @param offsetModifier The modifier to apply to the offset for centering.
191
132
  */
192
- getOptimalPopoverPosition(desiredPosition, availableSpace, boundElemSizes, offsetModifier) {
133
+ getOptimalPopoverPosition(desiredPosition, availableSpace) {
193
134
  const hostWidth = this.host.offsetWidth;
194
135
  const hostHeight = this.host.offsetHeight;
195
- // Check if the desired position has enough space
136
+ const boundElementWidth = this.boundElement.getBoundingClientRect().width;
137
+ const boundElementHeight = this.boundElement.getBoundingClientRect().height;
138
+ const offsetModifier = this.offsetModifier;
139
+ /** Check if there is enough space to fit the popover in the desired position */
196
140
  const fits = (pos) => {
197
141
  switch (pos) {
198
142
  case PopoverPosition.TOP:
199
- return (availableSpace.top >= hostHeight &&
200
- this.hasCenteredHorizontalSpace(availableSpace.left, availableSpace.right, hostWidth, boundElemSizes.width, offsetModifier));
143
+ return (availableSpace.top >= hostHeight - this.spaceTolerance &&
144
+ this.hasCenteredHorizontalSpace(availableSpace.left, availableSpace.right, hostWidth, boundElementWidth));
201
145
  case PopoverPosition.TOP_RIGHT:
202
146
  return (availableSpace.top >= hostHeight &&
203
- this.hasOffsetSpace(availableSpace.right, hostWidth, boundElemSizes.width, offsetModifier));
147
+ this.hasEnoughSideSpace(availableSpace.right, hostWidth, boundElementWidth, offsetModifier));
204
148
  case PopoverPosition.TOP_LEFT:
205
149
  return (availableSpace.top >= hostHeight &&
206
- this.hasOffsetSpace(availableSpace.left, hostWidth, boundElemSizes.width, offsetModifier));
150
+ this.hasEnoughSideSpace(availableSpace.left, hostWidth, boundElementWidth, offsetModifier));
207
151
  case PopoverPosition.RIGHT:
208
152
  return (availableSpace.right >= hostWidth &&
209
- this.hasCenteredVerticalSpace(availableSpace.top, availableSpace.bottom, hostHeight, boundElemSizes.height, offsetModifier));
153
+ this.hasCenteredVerticalSpace(availableSpace.top, availableSpace.bottom, hostHeight, boundElementHeight));
210
154
  case PopoverPosition.RIGHT_BOTTOM:
211
155
  return (availableSpace.right >= hostWidth &&
212
- this.hasOffsetSpace(availableSpace.bottom, hostHeight, boundElemSizes.height, offsetModifier));
156
+ this.hasEnoughSideSpace(availableSpace.bottom, hostHeight, boundElementHeight, offsetModifier));
213
157
  case PopoverPosition.RIGHT_TOP:
214
158
  return (availableSpace.right >= hostWidth &&
215
- this.hasOffsetSpace(availableSpace.top, hostHeight, boundElemSizes.height, offsetModifier));
159
+ this.hasEnoughSideSpace(availableSpace.top, hostHeight, boundElementHeight, offsetModifier));
216
160
  case PopoverPosition.BOTTOM:
217
161
  return (availableSpace.bottom >= hostHeight &&
218
- this.hasCenteredHorizontalSpace(availableSpace.left, availableSpace.right, hostWidth, boundElemSizes.width, offsetModifier));
162
+ this.hasCenteredHorizontalSpace(availableSpace.left, availableSpace.right, hostWidth, boundElementWidth));
219
163
  case PopoverPosition.BOTTOM_LEFT:
220
164
  return (availableSpace.bottom >= hostHeight &&
221
- this.hasOffsetSpace(availableSpace.left, hostWidth, boundElemSizes.width, offsetModifier));
165
+ this.hasEnoughSideSpace(availableSpace.left, hostWidth, boundElementWidth, offsetModifier));
222
166
  case PopoverPosition.BOTTOM_RIGHT:
223
167
  return (availableSpace.bottom >= hostHeight &&
224
- this.hasOffsetSpace(availableSpace.right, hostWidth, boundElemSizes.width, offsetModifier));
168
+ this.hasEnoughSideSpace(availableSpace.right, hostWidth, boundElementWidth, offsetModifier));
225
169
  case PopoverPosition.LEFT:
226
170
  return (availableSpace.left >= hostWidth &&
227
- this.hasCenteredVerticalSpace(availableSpace.top, availableSpace.bottom, hostHeight, boundElemSizes.height, offsetModifier));
171
+ this.hasCenteredVerticalSpace(availableSpace.top, availableSpace.bottom, hostHeight, boundElementHeight));
228
172
  case PopoverPosition.LEFT_TOP:
229
173
  return (availableSpace.left >= hostWidth &&
230
- this.hasOffsetSpace(availableSpace.top, hostHeight, boundElemSizes.height, offsetModifier));
174
+ this.hasEnoughSideSpace(availableSpace.top, hostHeight, boundElementHeight, offsetModifier));
231
175
  case PopoverPosition.LEFT_BOTTOM:
232
176
  return (availableSpace.left >= hostWidth &&
233
- this.hasOffsetSpace(availableSpace.bottom, hostHeight, boundElemSizes.height, offsetModifier));
177
+ this.hasEnoughSideSpace(availableSpace.bottom, hostHeight, boundElementHeight, offsetModifier));
234
178
  default:
235
179
  return false;
236
180
  }
@@ -256,27 +200,25 @@ const ZPopover = /*@__PURE__*/ proxyCustomElement(class ZPopover extends HTMLEle
256
200
  // If no position fits, find the best fallback based on available space
257
201
  return this.findBestFallbackPosition(availableSpace);
258
202
  }
259
- /**
260
- * Find the best fallback position based on available space when no position fits perfectly
261
- */
203
+ /** Find the best fallback position based on available space when no position fits perfectly. */
262
204
  findBestFallbackPosition(availableSpace) {
263
- // Determine the directions with the most space
205
+ // Determine which horizontal and vertical direction has the most available space
264
206
  const bestHorizontalDirection = availableSpace.right >= availableSpace.left ? PopoverPosition.RIGHT : PopoverPosition.LEFT;
265
207
  const bestVerticalDirection = availableSpace.bottom >= availableSpace.top ? PopoverPosition.BOTTOM : PopoverPosition.TOP;
266
- // Choose the main direction based on which has more space
208
+ // Choose the main direction based on which axis has more space overall
267
209
  const maxHorizontalSpace = Math.max(availableSpace.right, availableSpace.left);
268
210
  const maxVerticalSpace = Math.max(availableSpace.bottom, availableSpace.top);
269
211
  const mainDirection = maxVerticalSpace >= maxHorizontalSpace ? bestVerticalDirection : bestHorizontalDirection;
270
- // Check if secondary direction is necessary
271
- // Only add secondary direction if the difference between min and max in that direction is at least double
212
+ // Decide if a secondary direction is needed
213
+ // Only add a secondary direction if the difference between min and max in that axis is at least double
272
214
  let needsSecondaryDirection = false;
273
215
  if (mainDirection === bestVerticalDirection) {
274
- // Main direction is vertical, check horizontal space difference
216
+ // If main direction is vertical, check horizontal space difference
275
217
  const minHorizontalSpace = Math.min(availableSpace.right, availableSpace.left);
276
218
  needsSecondaryDirection = maxHorizontalSpace >= minHorizontalSpace * 2;
277
219
  }
278
220
  else {
279
- // Main direction is horizontal, check vertical space difference
221
+ // If main direction is horizontal, check vertical space difference
280
222
  const minVerticalSpace = Math.min(availableSpace.bottom, availableSpace.top);
281
223
  needsSecondaryDirection = maxVerticalSpace >= minVerticalSpace * 2;
282
224
  }
@@ -284,169 +226,194 @@ const ZPopover = /*@__PURE__*/ proxyCustomElement(class ZPopover extends HTMLEle
284
226
  return mainDirection;
285
227
  }
286
228
  const secondaryDirection = mainDirection === bestVerticalDirection ? bestHorizontalDirection : bestVerticalDirection;
287
- // Create a combined position (e.g., "bottom_right")
229
+ // Return a combined position (e.g., "bottom_right")
288
230
  return `${mainDirection}_${secondaryDirection}`;
289
231
  }
290
232
  /**
291
- * Calculate available space around the bound element
233
+ * Calculate available space around the element bound with the popover, based on its nearest scrollable ancestor.
234
+ *
235
+ * Calculations for `right` and `bottom` can be a little bit confusing because `boundingRect.right` and `bottom` may not be what you expect...
236
+ * For more information see the explanation in the docs.
237
+ * @link https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect#return_value
292
238
  */
293
- calculateAvailableSpace(boundElementRect, scrollContainer, scrollingBoundingRect) {
294
- const top = boundElementRect.top - scrollContainer.scrollTop;
295
- const bottom = scrollingBoundingRect.height - (boundElementRect.top + boundElementRect.height) + scrollContainer.scrollTop;
296
- const left = boundElementRect.left - scrollContainer.scrollLeft;
297
- const right = scrollingBoundingRect.width - (boundElementRect.left + boundElementRect.width) + scrollContainer.scrollLeft;
298
- const overflowBottom = Math.max(0, scrollingBoundingRect.top + scrollingBoundingRect.height - window.innerHeight);
299
- const overflowRight = Math.max(0, scrollingBoundingRect.left + scrollingBoundingRect.width - window.innerWidth);
300
- return {
301
- top: Math.min(top, top + scrollingBoundingRect.top),
302
- bottom: Math.min(bottom, bottom - overflowBottom),
303
- left: Math.min(left, left + scrollingBoundingRect.left),
304
- right: Math.min(right, right - overflowRight),
239
+ calculateAvailableSpace() {
240
+ const boundElementRect = this.boundElement.getBoundingClientRect();
241
+ if (this.lastBoundRect &&
242
+ this.lastBoundRect.x === boundElementRect.x &&
243
+ this.lastBoundRect.y === boundElementRect.y &&
244
+ this.lastBoundRect.width === boundElementRect.width &&
245
+ this.lastBoundRect.height === boundElementRect.height &&
246
+ this.cachedAvailableSpace) {
247
+ // If the bound element's rect hasn't changed, return the cached rect
248
+ return this.cachedAvailableSpace;
249
+ }
250
+ this.lastBoundRect = boundElementRect;
251
+ const scrollableParent = findScrollableParent(this.boundElement);
252
+ const scrollableParentRect = scrollableParent.getBoundingClientRect();
253
+ const hasNestedScrollableParent = scrollableParent !== this.boundElement.ownerDocument.documentElement;
254
+ const documentWidth = this.boundElement.ownerDocument.documentElement.clientWidth;
255
+ const documentHeight = this.boundElement.ownerDocument.documentElement.clientHeight;
256
+ const safeSpace = 8; // extra space to avoid popover being too close to the edges
257
+ // These deltas represent the offset between the scrollable parent and the viewport.
258
+ // They are used to adjust the available space calculations when the scrollable parent is not the document or body,
259
+ // to try to fit the popover inside the scrollable parent.
260
+ const deltaTop = hasNestedScrollableParent ? scrollableParentRect.top : 0;
261
+ const deltaRight = hasNestedScrollableParent ? documentWidth - scrollableParentRect.right : 0;
262
+ const deltaBottom = hasNestedScrollableParent ? documentHeight - scrollableParentRect.bottom : 0;
263
+ const deltaLeft = hasNestedScrollableParent ? scrollableParentRect.left : 0;
264
+ this.cachedAvailableSpace = {
265
+ top: boundElementRect.top - deltaTop - safeSpace,
266
+ right: documentWidth - boundElementRect.right - deltaRight - safeSpace,
267
+ bottom: documentHeight - boundElementRect.bottom - deltaBottom - safeSpace,
268
+ left: boundElementRect.left - deltaLeft - safeSpace,
305
269
  };
270
+ return this.cachedAvailableSpace;
306
271
  }
307
- /**
308
- * Calculate relative offsets for positioning
309
- */
310
- calculateRelativeOffsets(boundElementRect, relativeBoundingRect) {
272
+ /** Calculate the space around an element relative to the viewport. */
273
+ calculateElementOffsets(element) {
274
+ const elementRect = element.getBoundingClientRect();
275
+ const viewportWidth = element.ownerDocument.documentElement.clientWidth;
276
+ const viewportHeight = element.ownerDocument.documentElement.clientHeight;
311
277
  return {
312
- top: boundElementRect.top - relativeBoundingRect.top,
313
- right: boundElementRect.right - relativeBoundingRect.right,
314
- bottom: boundElementRect.bottom - relativeBoundingRect.bottom,
315
- left: boundElementRect.left - relativeBoundingRect.left,
278
+ top: elementRect.top,
279
+ right: viewportWidth - elementRect.right,
280
+ bottom: viewportHeight - elementRect.bottom,
281
+ left: elementRect.left,
316
282
  };
317
283
  }
318
- /**
319
- * Apply positioning styles based on position
320
- */
321
- applyPositionStyles(position, style, offsets, boundElementSizes, availableSpace, offsetModifier, arrowModifier) {
322
- const distanceFromBound = 8; // 8px is the distance of the popover from the bound element
323
- // Reset all positioning properties
324
- style.top = "auto";
325
- style.right = "auto";
326
- style.bottom = "auto";
327
- style.left = "auto";
328
- style.maxWidth = "";
329
- style.maxHeight = "";
284
+ /** Apply positioning styles based on passed position. */
285
+ applyPositionStyles(position, availableSpace) {
286
+ const boundElementWidth = this.boundElement.offsetWidth;
287
+ const boundElementHeight = this.boundElement.offsetHeight;
288
+ /** Distance between the popover and the bound element */
289
+ const distanceFromBound = 8;
290
+ const offsetModifier = this.offsetModifier;
291
+ /** 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. */
292
+ const arrowModifier = this.showArrow && this.center ? 8 : 0;
293
+ const hostStyle = this.host.style;
294
+ const boundElementOffsets = this.calculateElementOffsets(this.boundElement);
295
+ let maxWidth;
296
+ let maxHeight;
330
297
  switch (position) {
331
298
  case PopoverPosition.TOP:
332
299
  case PopoverPosition.TOP_RIGHT:
333
- style.bottom = `${offsets.bottom + boundElementSizes.height}px`;
334
- style.left = `${offsets.left + boundElementSizes.width * offsetModifier - (position === PopoverPosition.TOP_RIGHT ? arrowModifier : 0)}px`;
335
- style.maxHeight = `${availableSpace.top - distanceFromBound}px`;
300
+ hostStyle.bottom = `${boundElementOffsets.bottom + boundElementHeight}px`;
301
+ hostStyle.left = `${boundElementOffsets.left + boundElementWidth * offsetModifier - (position === PopoverPosition.TOP_RIGHT ? arrowModifier : 0)}px`;
302
+ maxHeight = availableSpace.top - distanceFromBound;
336
303
  if (position === PopoverPosition.TOP_RIGHT) {
337
- style.maxWidth = `${availableSpace.right + boundElementSizes.width * offsetModifier}px`;
304
+ maxWidth = availableSpace.right + boundElementWidth * offsetModifier;
338
305
  }
339
306
  break;
340
307
  case PopoverPosition.TOP_LEFT:
341
- style.right = `${offsets.right + boundElementSizes.width * offsetModifier - arrowModifier}px`;
342
- style.bottom = `${offsets.bottom + boundElementSizes.height}px`;
343
- style.maxWidth = `${availableSpace.left}px`;
344
- style.maxHeight = `${availableSpace.top - distanceFromBound}px`;
308
+ hostStyle.right = `${boundElementOffsets.right + boundElementWidth * offsetModifier - arrowModifier}px`;
309
+ hostStyle.bottom = `${boundElementOffsets.bottom + boundElementHeight}px`;
310
+ maxWidth = availableSpace.left + boundElementWidth * offsetModifier;
311
+ maxHeight = availableSpace.top - distanceFromBound;
345
312
  break;
346
313
  case PopoverPosition.BOTTOM:
347
314
  case PopoverPosition.BOTTOM_RIGHT:
348
- style.top = `${offsets.top + boundElementSizes.height}px`;
349
- style.left = `${offsets.left + boundElementSizes.width * offsetModifier - (position === PopoverPosition.BOTTOM_RIGHT ? arrowModifier : 0)}px`;
350
- style.maxHeight = `${availableSpace.bottom - distanceFromBound}px`;
315
+ hostStyle.top = `${boundElementOffsets.top + boundElementHeight}px`;
316
+ hostStyle.left = `${boundElementOffsets.left + boundElementWidth * offsetModifier - (position === PopoverPosition.BOTTOM_RIGHT ? arrowModifier : 0)}px`;
317
+ maxHeight = availableSpace.bottom - distanceFromBound;
351
318
  if (position === PopoverPosition.BOTTOM_RIGHT) {
352
- style.maxWidth = `${availableSpace.right + boundElementSizes.width * offsetModifier}px`;
319
+ maxWidth = availableSpace.right + boundElementWidth * offsetModifier;
353
320
  }
354
321
  break;
355
322
  case PopoverPosition.BOTTOM_LEFT:
356
- style.top = `${offsets.top + boundElementSizes.height}px`;
357
- style.right = `${offsets.right + boundElementSizes.width * offsetModifier - arrowModifier}px`;
358
- style.maxWidth = `${availableSpace.left}px`;
359
- style.maxHeight = `${availableSpace.bottom - distanceFromBound}px`;
323
+ hostStyle.top = `${boundElementOffsets.top + boundElementHeight}px`;
324
+ hostStyle.right = `${boundElementOffsets.right + boundElementWidth * offsetModifier - arrowModifier}px`;
325
+ maxWidth = availableSpace.left + boundElementWidth * offsetModifier;
326
+ maxHeight = availableSpace.bottom - distanceFromBound;
360
327
  break;
361
328
  case PopoverPosition.RIGHT:
362
329
  case PopoverPosition.RIGHT_BOTTOM:
363
- style.top = `${offsets.top + boundElementSizes.height * offsetModifier - (position === PopoverPosition.RIGHT_BOTTOM ? arrowModifier : 0)}px`;
364
- style.left = `${offsets.left + boundElementSizes.width}px`;
365
- style.maxWidth = `${availableSpace.right - distanceFromBound}px`;
330
+ hostStyle.top = `${boundElementOffsets.top + boundElementHeight * offsetModifier - (position === PopoverPosition.RIGHT_BOTTOM ? arrowModifier : 0)}px`;
331
+ hostStyle.left = `${boundElementOffsets.left + boundElementWidth}px`;
332
+ maxWidth = availableSpace.right - distanceFromBound;
366
333
  if (position === PopoverPosition.RIGHT) {
367
- style.maxHeight = `${Math.min(availableSpace.top + availableSpace.bottom + boundElementSizes.height, window.innerHeight - 20)}px`;
334
+ maxHeight = availableSpace.top + availableSpace.bottom + boundElementHeight;
368
335
  }
369
336
  else {
370
- style.maxHeight = `${availableSpace.bottom + boundElementSizes.height * offsetModifier}px`;
337
+ maxHeight = availableSpace.bottom + boundElementHeight * offsetModifier;
371
338
  }
372
339
  break;
373
340
  case PopoverPosition.RIGHT_TOP:
374
- style.bottom = `${offsets.bottom + boundElementSizes.height * offsetModifier - arrowModifier}px`;
375
- style.left = `${offsets.left + boundElementSizes.width}px`;
376
- style.maxWidth = `${availableSpace.right - distanceFromBound}px`;
377
- if (position === PopoverPosition.RIGHT_TOP) {
378
- style.maxHeight = `${availableSpace.top + boundElementSizes.height * offsetModifier}px`;
379
- }
341
+ hostStyle.bottom = `${boundElementOffsets.bottom + boundElementHeight * offsetModifier - arrowModifier}px`;
342
+ hostStyle.left = `${boundElementOffsets.left + boundElementWidth}px`;
343
+ maxWidth = availableSpace.right - distanceFromBound;
344
+ maxHeight = availableSpace.top + boundElementHeight * offsetModifier;
380
345
  break;
381
346
  case PopoverPosition.LEFT:
382
347
  case PopoverPosition.LEFT_BOTTOM:
383
- style.top = `${offsets.top + boundElementSizes.height * offsetModifier - (position === PopoverPosition.LEFT_BOTTOM ? arrowModifier : 0)}px`;
384
- style.right = `${offsets.right + boundElementSizes.width}px`;
385
- style.maxWidth = `${availableSpace.left - distanceFromBound}px`;
348
+ hostStyle.top = `${boundElementOffsets.top + boundElementHeight * offsetModifier - (position === PopoverPosition.LEFT_BOTTOM ? arrowModifier : 0)}px`;
349
+ hostStyle.right = `${boundElementOffsets.right + boundElementWidth}px`;
350
+ maxWidth = availableSpace.left - distanceFromBound;
386
351
  if (position === PopoverPosition.LEFT_BOTTOM) {
387
- style.maxHeight = `${availableSpace.bottom + boundElementSizes.height * offsetModifier}px`;
352
+ maxHeight = availableSpace.bottom + boundElementHeight * offsetModifier;
388
353
  }
389
354
  break;
390
355
  case PopoverPosition.LEFT_TOP:
391
- style.right = `${offsets.right + boundElementSizes.width}px`;
392
- style.bottom = `${offsets.bottom + boundElementSizes.height * offsetModifier - arrowModifier}px`;
393
- style.maxWidth = `${availableSpace.left - distanceFromBound}px`;
394
- if (position === PopoverPosition.LEFT_TOP) {
395
- style.maxHeight = `${availableSpace.top + boundElementSizes.height * offsetModifier}px`;
396
- }
356
+ hostStyle.right = `${boundElementOffsets.right + boundElementWidth}px`;
357
+ hostStyle.bottom = `${boundElementOffsets.bottom + boundElementHeight * offsetModifier - arrowModifier}px`;
358
+ maxWidth = availableSpace.left - distanceFromBound;
359
+ maxHeight = availableSpace.top + boundElementHeight * offsetModifier;
397
360
  break;
398
361
  }
362
+ if (getDevice() !== Device.MOBILE) {
363
+ // Only force max sizes on non-mobile viewports
364
+ hostStyle.maxWidth = maxWidth ? `${maxWidth}px` : "";
365
+ hostStyle.maxHeight = maxHeight ? `${maxHeight}px` : "";
366
+ }
399
367
  }
400
- /**
401
- * Set the position of the popover.
402
- */
368
+ /** Set the position of the popover. */
403
369
  setPosition() {
404
- let boundElement;
405
- if (typeof this.bindTo === "string") {
406
- boundElement = this.host.ownerDocument.querySelector(this.bindTo);
407
- }
408
- else if (this.bindTo) {
409
- boundElement = this.bindTo;
410
- }
411
- else {
412
- boundElement = this.host.parentElement;
370
+ if (!this.boundElement) {
371
+ return;
413
372
  }
414
- if (!boundElement) {
373
+ if (!isElementVisibleInContainer(this.boundElement, findScrollableParent(this.boundElement))) {
374
+ // If the bound element is not visible, hide the popover too
375
+ this.open = false;
415
376
  return;
416
377
  }
417
- const scrollContainer = findScrollableParent(boundElement);
418
- const scrollingBoundingRect = scrollContainer.getBoundingClientRect();
419
- const offsetContainer = this.host.offsetParent;
420
- const relativeBoundingRect = offsetContainer
421
- ? computeOffset(offsetContainer, scrollContainer)
422
- : { top: 0, right: 0, bottom: 0, left: 0 };
423
- const boundElementRect = computeOffset(boundElement, scrollContainer);
424
- const availableSpace = this.calculateAvailableSpace(boundElementRect, scrollContainer, scrollingBoundingRect);
425
- const offsets = this.calculateRelativeOffsets(boundElementRect, relativeBoundingRect);
426
- const offsetModifier = this.center ? 0.5 : 0;
427
- const arrowModifier = this.showArrow && this.center ? 8 : 0; // 8px is the distance of the arrow center from the edge of the popover
428
- const position = this.getOptimalPopoverPosition(this.position, availableSpace, { width: boundElementRect.width, height: boundElementRect.height }, offsetModifier);
429
- const style = this.host.style;
430
- this.applyPositionStyles(position, style, offsets, boundElementRect, availableSpace, offsetModifier, arrowModifier);
378
+ Object.assign(this.host.style, {
379
+ // Reset all positioning properties
380
+ top: "auto",
381
+ right: "auto",
382
+ bottom: "auto",
383
+ left: "auto",
384
+ maxWidth: "",
385
+ maxHeight: "",
386
+ // Set initial visibility to hidden while calculating position...
387
+ visibility: "hidden",
388
+ });
389
+ const availableSpace = this.calculateAvailableSpace();
390
+ const position = this.getOptimalPopoverPosition(this.position, availableSpace);
391
+ this.applyPositionStyles(position, availableSpace);
431
392
  this.currentPosition = position;
393
+ this.positionChange.emit({ position: this.currentPosition });
394
+ // ...then restore the visibility
395
+ this.host.style.visibility = "visible";
432
396
  }
433
397
  componentWillLoad() {
434
398
  this.validatePosition(this.position);
435
- this.onOpen();
436
399
  }
437
400
  componentDidLoad() {
438
- this.setPosition();
401
+ this.findBoundElement();
402
+ if (this.open) {
403
+ this.onOpen();
404
+ }
439
405
  }
440
406
  disconnectedCallback() {
441
407
  cancelAnimationFrame(this.animationFrameRequestId);
442
408
  }
443
409
  render() {
444
- return (h(Host, { key: '8628b0f299deb808e4c554047c76b82f392782c9', "current-position": this.currentPosition }, h("slot", { key: '144294e8216d7ad673e4ee3a96651c053703d135' })));
410
+ return (h(Host, { key: '1eafd1bd08aa31a81378354542b0e74edc4cb0ce', "current-position": this.currentPosition }, h("slot", { key: '2ad916cf0e13766e2e5f92f4f964a4fe909cdc7a' })));
445
411
  }
446
412
  get host() { return this; }
447
413
  static get watchers() { return {
448
414
  "position": ["validatePosition"],
449
- "open": ["onOpen"]
415
+ "open": ["onOpen"],
416
+ "bindTo": ["onBindingChange"]
450
417
  }; }
451
418
  static get style() { return ZPopoverStyle0; }
452
419
  }, [1, "z-popover", {
@@ -459,21 +426,22 @@ const ZPopover = /*@__PURE__*/ proxyCustomElement(class ZPopover extends HTMLEle
459
426
  "currentPosition": [32]
460
427
  }, [[8, "keyup", "closePopoverWithKeyboard"], [18, "click", "handleOutsideClick"]], {
461
428
  "position": ["validatePosition"],
462
- "open": ["onOpen"]
429
+ "open": ["onOpen"],
430
+ "bindTo": ["onBindingChange"]
463
431
  }]);
464
432
  // Clockwise order of positions.
465
433
  ZPopover.positionOrder = [
466
- PopoverPosition.TOP_RIGHT,
467
434
  PopoverPosition.TOP,
435
+ PopoverPosition.TOP_RIGHT,
468
436
  PopoverPosition.TOP_LEFT,
469
- PopoverPosition.RIGHT_BOTTOM,
470
437
  PopoverPosition.RIGHT,
438
+ PopoverPosition.RIGHT_BOTTOM,
471
439
  PopoverPosition.RIGHT_TOP,
472
- PopoverPosition.BOTTOM_LEFT,
473
440
  PopoverPosition.BOTTOM,
441
+ PopoverPosition.BOTTOM_LEFT,
474
442
  PopoverPosition.BOTTOM_RIGHT,
475
- PopoverPosition.LEFT_TOP,
476
443
  PopoverPosition.LEFT,
444
+ PopoverPosition.LEFT_TOP,
477
445
  PopoverPosition.LEFT_BOTTOM,
478
446
  ];
479
447
  function defineCustomElement() {