123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341 |
- import {
- FloatingCSS,
- connectFloatingUI,
- defaultOffsetDistance,
- disconnectFloatingUI,
- reposition,
- updateAfterClose
- } from "./chunk-LPWNO2ZS.js";
- import {
- guid,
- isPrimaryPointerButton,
- queryElementRoots,
- toAriaBoolean
- } from "./chunk-2TTT3V5O.js";
- import {
- H,
- Host,
- h,
- proxyCustomElement
- } from "./chunk-IOZKU7B2.js";
- // node_modules/@esri/calcite-components/dist/components/tooltip.js
- var CSS = {
- container: "container",
- arrow: "arrow"
- };
- var TOOLTIP_DELAY_MS = 500;
- var ARIA_DESCRIBED_BY = "aria-describedby";
- var TooltipManager = class {
- constructor() {
- this.registeredElements = /* @__PURE__ */ new WeakMap();
- this.hoverTimeouts = /* @__PURE__ */ new WeakMap();
- this.registeredElementCount = 0;
- this.queryTooltip = (composedPath) => {
- const { registeredElements } = this;
- const registeredElement = composedPath.find((pathEl) => registeredElements.has(pathEl));
- return registeredElements.get(registeredElement);
- };
- this.keyDownHandler = (event) => {
- if (event.key === "Escape") {
- const { activeTooltipEl } = this;
- if (activeTooltipEl) {
- this.clearHoverTimeout(activeTooltipEl);
- this.toggleTooltip(activeTooltipEl, false);
- }
- }
- };
- this.mouseEnterShow = (event) => {
- this.hoverEvent(event, true);
- };
- this.mouseLeaveHide = (event) => {
- this.hoverEvent(event, false);
- };
- this.clickHandler = (event) => {
- if (!isPrimaryPointerButton(event)) {
- return;
- }
- const clickedTooltip = this.queryTooltip(event.composedPath());
- this.clickedTooltip = clickedTooltip;
- if (clickedTooltip === null || clickedTooltip === void 0 ? void 0 : clickedTooltip.closeOnClick) {
- this.toggleTooltip(clickedTooltip, false);
- this.clearHoverTimeout(clickedTooltip);
- }
- };
- this.focusShow = (event) => {
- this.focusEvent(event, true);
- };
- this.blurHide = (event) => {
- this.focusEvent(event, false);
- };
- this.hoverToggle = (tooltip, value) => {
- const { hoverTimeouts } = this;
- hoverTimeouts.delete(tooltip);
- if (value) {
- this.closeExistingTooltip();
- }
- this.toggleTooltip(tooltip, value);
- };
- }
- registerElement(referenceEl, tooltip) {
- this.registeredElementCount++;
- this.registeredElements.set(referenceEl, tooltip);
- if (this.registeredElementCount === 1) {
- this.addListeners();
- }
- }
- unregisterElement(referenceEl) {
- if (this.registeredElements.delete(referenceEl)) {
- this.registeredElementCount--;
- }
- if (this.registeredElementCount === 0) {
- this.removeListeners();
- }
- }
- addListeners() {
- document.addEventListener("keydown", this.keyDownHandler);
- document.addEventListener("pointerover", this.mouseEnterShow, { capture: true });
- document.addEventListener("pointerout", this.mouseLeaveHide, { capture: true });
- document.addEventListener("pointerdown", this.clickHandler, { capture: true });
- document.addEventListener("focusin", this.focusShow, { capture: true });
- document.addEventListener("focusout", this.blurHide, { capture: true });
- }
- removeListeners() {
- document.removeEventListener("keydown", this.keyDownHandler);
- document.removeEventListener("pointerover", this.mouseEnterShow, { capture: true });
- document.removeEventListener("pointerout", this.mouseLeaveHide, { capture: true });
- document.removeEventListener("pointerdown", this.clickHandler, { capture: true });
- document.removeEventListener("focusin", this.focusShow, { capture: true });
- document.removeEventListener("focusout", this.blurHide, { capture: true });
- }
- clearHoverTimeout(tooltip) {
- const { hoverTimeouts } = this;
- if (hoverTimeouts.has(tooltip)) {
- window.clearTimeout(hoverTimeouts.get(tooltip));
- hoverTimeouts.delete(tooltip);
- }
- }
- closeExistingTooltip() {
- const { activeTooltipEl } = this;
- if (activeTooltipEl) {
- this.toggleTooltip(activeTooltipEl, false);
- }
- }
- focusTooltip(tooltip, value) {
- this.closeExistingTooltip();
- if (value) {
- this.clearHoverTimeout(tooltip);
- }
- this.toggleTooltip(tooltip, value);
- }
- toggleTooltip(tooltip, value) {
- tooltip.open = value;
- if (value) {
- this.activeTooltipEl = tooltip;
- }
- }
- hoverTooltip(tooltip, value) {
- this.clearHoverTimeout(tooltip);
- const { hoverTimeouts } = this;
- const timeoutId = window.setTimeout(() => this.hoverToggle(tooltip, value), TOOLTIP_DELAY_MS);
- hoverTimeouts.set(tooltip, timeoutId);
- }
- activeTooltipHover(event) {
- const { activeTooltipEl, hoverTimeouts } = this;
- const { type } = event;
- if (!activeTooltipEl) {
- return;
- }
- if (type === "pointerover" && event.composedPath().includes(activeTooltipEl)) {
- this.clearHoverTimeout(activeTooltipEl);
- } else if (type === "pointerout" && !hoverTimeouts.has(activeTooltipEl)) {
- this.hoverTooltip(activeTooltipEl, false);
- }
- }
- hoverEvent(event, value) {
- const tooltip = this.queryTooltip(event.composedPath());
- this.activeTooltipHover(event);
- if (!tooltip) {
- return;
- }
- this.hoverTooltip(tooltip, value);
- }
- focusEvent(event, value) {
- const tooltip = this.queryTooltip(event.composedPath());
- if (!tooltip || tooltip === this.clickedTooltip) {
- this.clickedTooltip = null;
- return;
- }
- this.focusTooltip(tooltip, value);
- }
- };
- 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)}';
- var manager = new TooltipManager();
- var Tooltip = proxyCustomElement(class extends H {
- constructor() {
- super();
- this.__registerHost();
- this.__attachShadow();
- this.closeOnClick = false;
- this.offsetDistance = defaultOffsetDistance;
- this.offsetSkidding = 0;
- this.open = false;
- this.overlayPositioning = "absolute";
- this.placement = "auto";
- this.guid = `calcite-tooltip-${guid()}`;
- this.hasLoaded = false;
- this.setUpReferenceElement = (warn = true) => {
- this.removeReferences();
- this.effectiveReferenceElement = this.getReferenceElement();
- connectFloatingUI(this, this.effectiveReferenceElement, this.el);
- const { el, referenceElement, effectiveReferenceElement } = this;
- if (warn && referenceElement && !effectiveReferenceElement) {
- console.warn(`${el.tagName}: reference-element id "${referenceElement}" was not found.`, {
- el
- });
- }
- this.addReferences();
- };
- this.getId = () => {
- return this.el.id || this.guid;
- };
- this.addReferences = () => {
- const { effectiveReferenceElement } = this;
- if (!effectiveReferenceElement) {
- return;
- }
- const id = this.getId();
- if ("setAttribute" in effectiveReferenceElement) {
- effectiveReferenceElement.setAttribute(ARIA_DESCRIBED_BY, id);
- }
- manager.registerElement(effectiveReferenceElement, this.el);
- };
- this.removeReferences = () => {
- const { effectiveReferenceElement } = this;
- if (!effectiveReferenceElement) {
- return;
- }
- if ("removeAttribute" in effectiveReferenceElement) {
- effectiveReferenceElement.removeAttribute(ARIA_DESCRIBED_BY);
- }
- manager.unregisterElement(effectiveReferenceElement);
- };
- }
- offsetDistanceOffsetHandler() {
- this.reposition(true);
- }
- offsetSkiddingHandler() {
- this.reposition(true);
- }
- openHandler(value) {
- if (value) {
- this.reposition(true);
- } else {
- updateAfterClose(this.el);
- }
- }
- overlayPositioningHandler() {
- this.reposition(true);
- }
- placementHandler() {
- this.reposition(true);
- }
- referenceElementHandler() {
- this.setUpReferenceElement();
- }
- connectedCallback() {
- this.setUpReferenceElement(this.hasLoaded);
- }
- componentDidLoad() {
- if (this.referenceElement && !this.effectiveReferenceElement) {
- this.setUpReferenceElement();
- }
- this.reposition(true);
- this.hasLoaded = true;
- }
- disconnectedCallback() {
- this.removeReferences();
- disconnectFloatingUI(this, this.effectiveReferenceElement, this.el);
- }
- async reposition(delayed = false) {
- const { el, effectiveReferenceElement, placement, overlayPositioning, offsetDistance, offsetSkidding, arrowEl } = this;
- return reposition(this, {
- floatingEl: el,
- referenceEl: effectiveReferenceElement,
- overlayPositioning,
- placement,
- offsetDistance,
- offsetSkidding,
- includeArrow: true,
- arrowEl,
- type: "tooltip"
- }, delayed);
- }
- getReferenceElement() {
- const { referenceElement, el } = this;
- return (typeof referenceElement === "string" ? queryElementRoots(el, { id: referenceElement }) : referenceElement) || null;
- }
- render() {
- const { effectiveReferenceElement, label, open } = this;
- const displayed = effectiveReferenceElement && open;
- const hidden = !displayed;
- 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: {
- [FloatingCSS.animation]: true,
- [FloatingCSS.animationActive]: displayed
- } }, h("div", { class: CSS.arrow, ref: (arrowEl) => this.arrowEl = arrowEl }), h("div", { class: CSS.container }, h("slot", null))));
- }
- get el() {
- return this;
- }
- static get watchers() {
- return {
- "offsetDistance": ["offsetDistanceOffsetHandler"],
- "offsetSkidding": ["offsetSkiddingHandler"],
- "open": ["openHandler"],
- "overlayPositioning": ["overlayPositioningHandler"],
- "placement": ["placementHandler"],
- "referenceElement": ["referenceElementHandler"]
- };
- }
- static get style() {
- return tooltipCss;
- }
- }, [1, "calcite-tooltip", {
- "closeOnClick": [516, "close-on-click"],
- "label": [1],
- "offsetDistance": [514, "offset-distance"],
- "offsetSkidding": [514, "offset-skidding"],
- "open": [516],
- "overlayPositioning": [513, "overlay-positioning"],
- "placement": [513],
- "referenceElement": [1, "reference-element"],
- "effectiveReferenceElement": [32],
- "reposition": [64]
- }]);
- function defineCustomElement() {
- if (typeof customElements === "undefined") {
- return;
- }
- const components = ["calcite-tooltip"];
- components.forEach((tagName) => {
- switch (tagName) {
- case "calcite-tooltip":
- if (!customElements.get(tagName)) {
- customElements.define(tagName, Tooltip);
- }
- break;
- }
- });
- }
- defineCustomElement();
- export {
- Tooltip,
- defineCustomElement
- };
- /*!
- * All material copyright ESRI, All Rights Reserved, unless otherwise specified.
- * See https://github.com/Esri/calcite-components/blob/master/LICENSE.md for details.
- * v1.0.0-beta.97
- */
- //# sourceMappingURL=chunk-ERKDZ5WT.js.map
|