chunk-ERKDZ5WT.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. import {
  2. FloatingCSS,
  3. connectFloatingUI,
  4. defaultOffsetDistance,
  5. disconnectFloatingUI,
  6. reposition,
  7. updateAfterClose
  8. } from "./chunk-LPWNO2ZS.js";
  9. import {
  10. guid,
  11. isPrimaryPointerButton,
  12. queryElementRoots,
  13. toAriaBoolean
  14. } from "./chunk-2TTT3V5O.js";
  15. import {
  16. H,
  17. Host,
  18. h,
  19. proxyCustomElement
  20. } from "./chunk-IOZKU7B2.js";
  21. // node_modules/@esri/calcite-components/dist/components/tooltip.js
  22. var CSS = {
  23. container: "container",
  24. arrow: "arrow"
  25. };
  26. var TOOLTIP_DELAY_MS = 500;
  27. var ARIA_DESCRIBED_BY = "aria-describedby";
  28. var TooltipManager = class {
  29. constructor() {
  30. this.registeredElements = /* @__PURE__ */ new WeakMap();
  31. this.hoverTimeouts = /* @__PURE__ */ new WeakMap();
  32. this.registeredElementCount = 0;
  33. this.queryTooltip = (composedPath) => {
  34. const { registeredElements } = this;
  35. const registeredElement = composedPath.find((pathEl) => registeredElements.has(pathEl));
  36. return registeredElements.get(registeredElement);
  37. };
  38. this.keyDownHandler = (event) => {
  39. if (event.key === "Escape") {
  40. const { activeTooltipEl } = this;
  41. if (activeTooltipEl) {
  42. this.clearHoverTimeout(activeTooltipEl);
  43. this.toggleTooltip(activeTooltipEl, false);
  44. }
  45. }
  46. };
  47. this.mouseEnterShow = (event) => {
  48. this.hoverEvent(event, true);
  49. };
  50. this.mouseLeaveHide = (event) => {
  51. this.hoverEvent(event, false);
  52. };
  53. this.clickHandler = (event) => {
  54. if (!isPrimaryPointerButton(event)) {
  55. return;
  56. }
  57. const clickedTooltip = this.queryTooltip(event.composedPath());
  58. this.clickedTooltip = clickedTooltip;
  59. if (clickedTooltip === null || clickedTooltip === void 0 ? void 0 : clickedTooltip.closeOnClick) {
  60. this.toggleTooltip(clickedTooltip, false);
  61. this.clearHoverTimeout(clickedTooltip);
  62. }
  63. };
  64. this.focusShow = (event) => {
  65. this.focusEvent(event, true);
  66. };
  67. this.blurHide = (event) => {
  68. this.focusEvent(event, false);
  69. };
  70. this.hoverToggle = (tooltip, value) => {
  71. const { hoverTimeouts } = this;
  72. hoverTimeouts.delete(tooltip);
  73. if (value) {
  74. this.closeExistingTooltip();
  75. }
  76. this.toggleTooltip(tooltip, value);
  77. };
  78. }
  79. registerElement(referenceEl, tooltip) {
  80. this.registeredElementCount++;
  81. this.registeredElements.set(referenceEl, tooltip);
  82. if (this.registeredElementCount === 1) {
  83. this.addListeners();
  84. }
  85. }
  86. unregisterElement(referenceEl) {
  87. if (this.registeredElements.delete(referenceEl)) {
  88. this.registeredElementCount--;
  89. }
  90. if (this.registeredElementCount === 0) {
  91. this.removeListeners();
  92. }
  93. }
  94. addListeners() {
  95. document.addEventListener("keydown", this.keyDownHandler);
  96. document.addEventListener("pointerover", this.mouseEnterShow, { capture: true });
  97. document.addEventListener("pointerout", this.mouseLeaveHide, { capture: true });
  98. document.addEventListener("pointerdown", this.clickHandler, { capture: true });
  99. document.addEventListener("focusin", this.focusShow, { capture: true });
  100. document.addEventListener("focusout", this.blurHide, { capture: true });
  101. }
  102. removeListeners() {
  103. document.removeEventListener("keydown", this.keyDownHandler);
  104. document.removeEventListener("pointerover", this.mouseEnterShow, { capture: true });
  105. document.removeEventListener("pointerout", this.mouseLeaveHide, { capture: true });
  106. document.removeEventListener("pointerdown", this.clickHandler, { capture: true });
  107. document.removeEventListener("focusin", this.focusShow, { capture: true });
  108. document.removeEventListener("focusout", this.blurHide, { capture: true });
  109. }
  110. clearHoverTimeout(tooltip) {
  111. const { hoverTimeouts } = this;
  112. if (hoverTimeouts.has(tooltip)) {
  113. window.clearTimeout(hoverTimeouts.get(tooltip));
  114. hoverTimeouts.delete(tooltip);
  115. }
  116. }
  117. closeExistingTooltip() {
  118. const { activeTooltipEl } = this;
  119. if (activeTooltipEl) {
  120. this.toggleTooltip(activeTooltipEl, false);
  121. }
  122. }
  123. focusTooltip(tooltip, value) {
  124. this.closeExistingTooltip();
  125. if (value) {
  126. this.clearHoverTimeout(tooltip);
  127. }
  128. this.toggleTooltip(tooltip, value);
  129. }
  130. toggleTooltip(tooltip, value) {
  131. tooltip.open = value;
  132. if (value) {
  133. this.activeTooltipEl = tooltip;
  134. }
  135. }
  136. hoverTooltip(tooltip, value) {
  137. this.clearHoverTimeout(tooltip);
  138. const { hoverTimeouts } = this;
  139. const timeoutId = window.setTimeout(() => this.hoverToggle(tooltip, value), TOOLTIP_DELAY_MS);
  140. hoverTimeouts.set(tooltip, timeoutId);
  141. }
  142. activeTooltipHover(event) {
  143. const { activeTooltipEl, hoverTimeouts } = this;
  144. const { type } = event;
  145. if (!activeTooltipEl) {
  146. return;
  147. }
  148. if (type === "pointerover" && event.composedPath().includes(activeTooltipEl)) {
  149. this.clearHoverTimeout(activeTooltipEl);
  150. } else if (type === "pointerout" && !hoverTimeouts.has(activeTooltipEl)) {
  151. this.hoverTooltip(activeTooltipEl, false);
  152. }
  153. }
  154. hoverEvent(event, value) {
  155. const tooltip = this.queryTooltip(event.composedPath());
  156. this.activeTooltipHover(event);
  157. if (!tooltip) {
  158. return;
  159. }
  160. this.hoverTooltip(tooltip, value);
  161. }
  162. focusEvent(event, value) {
  163. const tooltip = this.queryTooltip(event.composedPath());
  164. if (!tooltip || tooltip === this.clickedTooltip) {
  165. this.clickedTooltip = null;
  166. return;
  167. }
  168. this.focusTooltip(tooltip, value);
  169. }
  170. };
  171. var tooltipCss = '@keyframes in{0%{opacity:0}100%{opacity:1}}@keyframes in-down{0%{opacity:0;transform:translate3D(0, -5px, 0)}100%{opacity:1;transform:translate3D(0, 0, 0)}}@keyframes in-up{0%{opacity:0;transform:translate3D(0, 5px, 0)}100%{opacity:1;transform:translate3D(0, 0, 0)}}@keyframes in-scale{0%{opacity:0;transform:scale3D(0.95, 0.95, 1)}100%{opacity:1;transform:scale3D(1, 1, 1)}}:root{--calcite-animation-timing:calc(150ms * var(--calcite-internal-duration-factor));--calcite-internal-duration-factor:var(--calcite-duration-factor, 1);--calcite-internal-animation-timing-fast:calc(100ms * var(--calcite-internal-duration-factor));--calcite-internal-animation-timing-medium:calc(200ms * var(--calcite-internal-duration-factor));--calcite-internal-animation-timing-slow:calc(300ms * var(--calcite-internal-duration-factor))}.calcite-animate{opacity:0;animation-fill-mode:both;animation-duration:var(--calcite-animation-timing)}.calcite-animate__in{animation-name:in}.calcite-animate__in-down{animation-name:in-down}.calcite-animate__in-up{animation-name:in-up}.calcite-animate__in-scale{animation-name:in-scale}@media (prefers-reduced-motion: reduce){:root{--calcite-internal-duration-factor:0.01}}:root{--calcite-floating-ui-transition:var(--calcite-animation-timing)}:host([hidden]){display:none}:host{display:block;position:absolute;z-index:999}.calcite-floating-ui-anim{position:relative;transition:var(--calcite-floating-ui-transition);visibility:hidden;transition-property:transform, visibility, opacity;opacity:0;box-shadow:0 0 16px 0 rgba(0, 0, 0, 0.16);z-index:1;border-radius:0.25rem}:host([data-placement^=bottom]) .calcite-floating-ui-anim{transform:translateY(-5px)}:host([data-placement^=top]) .calcite-floating-ui-anim{transform:translateY(5px)}:host([data-placement^=left]) .calcite-floating-ui-anim{transform:translateX(5px)}:host([data-placement^=right]) .calcite-floating-ui-anim{transform:translateX(-5px)}:host([data-placement]) .calcite-floating-ui-anim--active{opacity:1;visibility:visible;transform:translate(0)}:host([calcite-hydrated-hidden]){visibility:hidden !important;pointer-events:none}.arrow,.arrow::before{position:absolute;inline-size:8px;block-size:8px;z-index:-1}.arrow::before{content:"";--tw-shadow:0 4px 8px -1px rgba(0, 0, 0, 0.08), 0 2px 4px -1px rgba(0, 0, 0, 0.04);--tw-shadow-colored:0 4px 8px -1px var(--tw-shadow-color), 0 2px 4px -1px var(--tw-shadow-color);box-shadow:var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow);transform:rotate(45deg);background:var(--calcite-ui-foreground-1)}:host([data-placement^=top]) .arrow{inset-block-end:-4px}:host([data-placement^=bottom]) .arrow{inset-block-start:-4px}:host([data-placement^=left]) .arrow{direction:ltr;inset-inline-end:-4px}:host([data-placement^=right]) .arrow{direction:ltr;inset-inline-start:-4px}.container{position:relative;overflow:hidden;border-radius:0.25rem;background-color:var(--calcite-ui-foreground-1);padding-block:0.75rem;padding-inline:1rem;font-size:var(--calcite-font-size--2);line-height:1.375;font-weight:var(--calcite-font-weight-medium);color:var(--calcite-ui-text-1);max-inline-size:20rem;max-block-size:20rem;text-align:start}.calcite-floating-ui-anim{border-radius:0.25rem;border-width:1px;border-style:solid;border-color:var(--calcite-ui-border-3);background-color:var(--calcite-ui-foreground-1)}.arrow::before{outline:1px solid var(--calcite-ui-border-3)}';
  172. var manager = new TooltipManager();
  173. var Tooltip = proxyCustomElement(class extends H {
  174. constructor() {
  175. super();
  176. this.__registerHost();
  177. this.__attachShadow();
  178. this.closeOnClick = false;
  179. this.offsetDistance = defaultOffsetDistance;
  180. this.offsetSkidding = 0;
  181. this.open = false;
  182. this.overlayPositioning = "absolute";
  183. this.placement = "auto";
  184. this.guid = `calcite-tooltip-${guid()}`;
  185. this.hasLoaded = false;
  186. this.setUpReferenceElement = (warn = true) => {
  187. this.removeReferences();
  188. this.effectiveReferenceElement = this.getReferenceElement();
  189. connectFloatingUI(this, this.effectiveReferenceElement, this.el);
  190. const { el, referenceElement, effectiveReferenceElement } = this;
  191. if (warn && referenceElement && !effectiveReferenceElement) {
  192. console.warn(`${el.tagName}: reference-element id "${referenceElement}" was not found.`, {
  193. el
  194. });
  195. }
  196. this.addReferences();
  197. };
  198. this.getId = () => {
  199. return this.el.id || this.guid;
  200. };
  201. this.addReferences = () => {
  202. const { effectiveReferenceElement } = this;
  203. if (!effectiveReferenceElement) {
  204. return;
  205. }
  206. const id = this.getId();
  207. if ("setAttribute" in effectiveReferenceElement) {
  208. effectiveReferenceElement.setAttribute(ARIA_DESCRIBED_BY, id);
  209. }
  210. manager.registerElement(effectiveReferenceElement, this.el);
  211. };
  212. this.removeReferences = () => {
  213. const { effectiveReferenceElement } = this;
  214. if (!effectiveReferenceElement) {
  215. return;
  216. }
  217. if ("removeAttribute" in effectiveReferenceElement) {
  218. effectiveReferenceElement.removeAttribute(ARIA_DESCRIBED_BY);
  219. }
  220. manager.unregisterElement(effectiveReferenceElement);
  221. };
  222. }
  223. offsetDistanceOffsetHandler() {
  224. this.reposition(true);
  225. }
  226. offsetSkiddingHandler() {
  227. this.reposition(true);
  228. }
  229. openHandler(value) {
  230. if (value) {
  231. this.reposition(true);
  232. } else {
  233. updateAfterClose(this.el);
  234. }
  235. }
  236. overlayPositioningHandler() {
  237. this.reposition(true);
  238. }
  239. placementHandler() {
  240. this.reposition(true);
  241. }
  242. referenceElementHandler() {
  243. this.setUpReferenceElement();
  244. }
  245. connectedCallback() {
  246. this.setUpReferenceElement(this.hasLoaded);
  247. }
  248. componentDidLoad() {
  249. if (this.referenceElement && !this.effectiveReferenceElement) {
  250. this.setUpReferenceElement();
  251. }
  252. this.reposition(true);
  253. this.hasLoaded = true;
  254. }
  255. disconnectedCallback() {
  256. this.removeReferences();
  257. disconnectFloatingUI(this, this.effectiveReferenceElement, this.el);
  258. }
  259. async reposition(delayed = false) {
  260. const { el, effectiveReferenceElement, placement, overlayPositioning, offsetDistance, offsetSkidding, arrowEl } = this;
  261. return reposition(this, {
  262. floatingEl: el,
  263. referenceEl: effectiveReferenceElement,
  264. overlayPositioning,
  265. placement,
  266. offsetDistance,
  267. offsetSkidding,
  268. includeArrow: true,
  269. arrowEl,
  270. type: "tooltip"
  271. }, delayed);
  272. }
  273. getReferenceElement() {
  274. const { referenceElement, el } = this;
  275. return (typeof referenceElement === "string" ? queryElementRoots(el, { id: referenceElement }) : referenceElement) || null;
  276. }
  277. render() {
  278. const { effectiveReferenceElement, label, open } = this;
  279. const displayed = effectiveReferenceElement && open;
  280. const hidden = !displayed;
  281. return h(Host, { "aria-hidden": toAriaBoolean(hidden), "aria-label": label, "aria-live": "polite", "calcite-hydrated-hidden": hidden, id: this.getId(), role: "tooltip" }, h("div", { class: {
  282. [FloatingCSS.animation]: true,
  283. [FloatingCSS.animationActive]: displayed
  284. } }, h("div", { class: CSS.arrow, ref: (arrowEl) => this.arrowEl = arrowEl }), h("div", { class: CSS.container }, h("slot", null))));
  285. }
  286. get el() {
  287. return this;
  288. }
  289. static get watchers() {
  290. return {
  291. "offsetDistance": ["offsetDistanceOffsetHandler"],
  292. "offsetSkidding": ["offsetSkiddingHandler"],
  293. "open": ["openHandler"],
  294. "overlayPositioning": ["overlayPositioningHandler"],
  295. "placement": ["placementHandler"],
  296. "referenceElement": ["referenceElementHandler"]
  297. };
  298. }
  299. static get style() {
  300. return tooltipCss;
  301. }
  302. }, [1, "calcite-tooltip", {
  303. "closeOnClick": [516, "close-on-click"],
  304. "label": [1],
  305. "offsetDistance": [514, "offset-distance"],
  306. "offsetSkidding": [514, "offset-skidding"],
  307. "open": [516],
  308. "overlayPositioning": [513, "overlay-positioning"],
  309. "placement": [513],
  310. "referenceElement": [1, "reference-element"],
  311. "effectiveReferenceElement": [32],
  312. "reposition": [64]
  313. }]);
  314. function defineCustomElement() {
  315. if (typeof customElements === "undefined") {
  316. return;
  317. }
  318. const components = ["calcite-tooltip"];
  319. components.forEach((tagName) => {
  320. switch (tagName) {
  321. case "calcite-tooltip":
  322. if (!customElements.get(tagName)) {
  323. customElements.define(tagName, Tooltip);
  324. }
  325. break;
  326. }
  327. });
  328. }
  329. defineCustomElement();
  330. export {
  331. Tooltip,
  332. defineCustomElement
  333. };
  334. /*!
  335. * All material copyright ESRI, All Rights Reserved, unless otherwise specified.
  336. * See https://github.com/Esri/calcite-components/blob/master/LICENSE.md for details.
  337. * v1.0.0-beta.97
  338. */
  339. //# sourceMappingURL=chunk-ERKDZ5WT.js.map