@diabolic/pointy 1.0.0 → 1.0.1

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.
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Pointy - A lightweight tooltip library with animated pointer
3
- * @version 1.0.0
3
+ * @version 1.0.1
4
4
  * @license MIT
5
5
  */
6
6
  /**
@@ -477,6 +477,8 @@ class Pointy {
477
477
  this.isVisible = false;
478
478
  this.isPointingUp = true; // Always start pointing up
479
479
  this.lastTargetY = null;
480
+ this._targetYHistory = []; // Track Y positions for velocity detection
481
+ this._lastDirectionChangeTime = 0; // Debounce direction changes
480
482
  this.manualDirection = null; // 'up', 'down', or null (auto)
481
483
  this.moveTimeout = null;
482
484
  this._hasShownBefore = false; // For intro animation
@@ -583,18 +585,37 @@ class Pointy {
583
585
  if (this.manualDirection !== null) {
584
586
  this.isPointingUp = this.manualDirection === 'up';
585
587
  } else {
586
- // Auto: Check if target is above or below previous position
588
+ // Auto: Track velocity over time to detect movement direction
587
589
  const currentTargetY = targetRect.top + scrollY;
588
- if (this.lastTargetY !== null) {
589
- const threshold = 50;
590
- if (currentTargetY < this.lastTargetY - threshold) {
591
- // Target moved UP - pointer below target, pointing up
592
- this.isPointingUp = true;
593
- } else if (currentTargetY > this.lastTargetY + threshold) {
594
- // Target moved DOWN - pointer above target, pointing down
595
- this.isPointingUp = false;
590
+ const now = Date.now();
591
+
592
+ // Add to history with timestamp
593
+ this._targetYHistory.push({ y: currentTargetY, time: now });
594
+
595
+ // Keep only last 200ms of history
596
+ const historyWindow = 200;
597
+ this._targetYHistory = this._targetYHistory.filter(h => now - h.time < historyWindow);
598
+
599
+ // Calculate velocity if we have enough history
600
+ if (this._targetYHistory.length >= 2) {
601
+ const oldest = this._targetYHistory[0];
602
+ const newest = this._targetYHistory[this._targetYHistory.length - 1];
603
+ const deltaY = newest.y - oldest.y;
604
+ newest.time - oldest.time;
605
+
606
+ // Only change direction if significant movement and debounce (300ms between changes)
607
+ const velocityThreshold = 30; // pixels moved in the history window
608
+ const debounceTime = 300;
609
+
610
+ if (Math.abs(deltaY) > velocityThreshold && (now - this._lastDirectionChangeTime) > debounceTime) {
611
+ const newDirection = deltaY < 0; // Moving up = true, moving down = false
612
+ if (newDirection !== this.isPointingUp) {
613
+ this.isPointingUp = newDirection;
614
+ this._lastDirectionChangeTime = now;
615
+ }
596
616
  }
597
617
  }
618
+
598
619
  this.lastTargetY = currentTargetY;
599
620
  }
600
621
 
@@ -1922,14 +1943,17 @@ class Pointy {
1922
1943
  pointTo(target, content, direction) {
1923
1944
  const previousTarget = this.targetElement;
1924
1945
 
1946
+ // Determine actual direction ('auto' means will be calculated in updatePosition)
1947
+ const actualDirection = direction || 'auto';
1948
+
1925
1949
  this._emit('beforePointTo', {
1926
1950
  target: Pointy.getTargetElement(target),
1927
1951
  content: content,
1928
- direction: direction,
1952
+ direction: actualDirection,
1929
1953
  fromTarget: previousTarget
1930
1954
  });
1931
1955
 
1932
- // Set manual direction
1956
+ // Set manual direction (null means auto)
1933
1957
  this.manualDirection = direction || null;
1934
1958
 
1935
1959
  // Pause floating animation during movement
@@ -1945,9 +1969,20 @@ class Pointy {
1945
1969
  content: content
1946
1970
  });
1947
1971
 
1972
+ this.targetElement = toTarget;
1973
+
1974
+ if (content !== undefined) {
1975
+ this._setMessages(content, false); // false = not from step change, don't auto-start cycle
1976
+ }
1977
+
1978
+ this.updatePosition();
1979
+
1980
+ // Get the resolved direction after updatePosition calculates it
1981
+ const resolvedDirection = this.isPointingUp ? 'up' : 'down';
1982
+
1948
1983
  this.moveTimeout = setTimeout(() => {
1949
1984
  this.container.classList.remove(this.classNames.moving);
1950
- this._emit('pointToComplete', { target: this.targetElement, content: content });
1985
+ this._emit('pointToComplete', { target: this.targetElement, content: content, direction: resolvedDirection });
1951
1986
  this._emit('animationEnd', {
1952
1987
  fromTarget: previousTarget,
1953
1988
  toTarget: this.targetElement,
@@ -1956,15 +1991,7 @@ class Pointy {
1956
1991
  });
1957
1992
  }, this.animationDuration);
1958
1993
 
1959
- this.targetElement = toTarget;
1960
-
1961
- if (content !== undefined) {
1962
- this._setMessages(content, false); // false = not from step change, don't auto-start cycle
1963
- }
1964
-
1965
- this.updatePosition();
1966
-
1967
- this._emit('pointTo', { target: this.targetElement, content: content, direction: direction });
1994
+ this._emit('pointTo', { target: this.targetElement, content: content, direction: resolvedDirection });
1968
1995
 
1969
1996
  // Make sure it's visible
1970
1997
  if (!this.isVisible) {
package/dist/pointy.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Pointy - A lightweight tooltip library with animated pointer
3
- * @version 1.0.0
3
+ * @version 1.0.1
4
4
  * @license MIT
5
5
  */
6
6
  (function (global, factory) {
@@ -483,6 +483,8 @@
483
483
  this.isVisible = false;
484
484
  this.isPointingUp = true; // Always start pointing up
485
485
  this.lastTargetY = null;
486
+ this._targetYHistory = []; // Track Y positions for velocity detection
487
+ this._lastDirectionChangeTime = 0; // Debounce direction changes
486
488
  this.manualDirection = null; // 'up', 'down', or null (auto)
487
489
  this.moveTimeout = null;
488
490
  this._hasShownBefore = false; // For intro animation
@@ -589,18 +591,37 @@
589
591
  if (this.manualDirection !== null) {
590
592
  this.isPointingUp = this.manualDirection === 'up';
591
593
  } else {
592
- // Auto: Check if target is above or below previous position
594
+ // Auto: Track velocity over time to detect movement direction
593
595
  const currentTargetY = targetRect.top + scrollY;
594
- if (this.lastTargetY !== null) {
595
- const threshold = 50;
596
- if (currentTargetY < this.lastTargetY - threshold) {
597
- // Target moved UP - pointer below target, pointing up
598
- this.isPointingUp = true;
599
- } else if (currentTargetY > this.lastTargetY + threshold) {
600
- // Target moved DOWN - pointer above target, pointing down
601
- this.isPointingUp = false;
596
+ const now = Date.now();
597
+
598
+ // Add to history with timestamp
599
+ this._targetYHistory.push({ y: currentTargetY, time: now });
600
+
601
+ // Keep only last 200ms of history
602
+ const historyWindow = 200;
603
+ this._targetYHistory = this._targetYHistory.filter(h => now - h.time < historyWindow);
604
+
605
+ // Calculate velocity if we have enough history
606
+ if (this._targetYHistory.length >= 2) {
607
+ const oldest = this._targetYHistory[0];
608
+ const newest = this._targetYHistory[this._targetYHistory.length - 1];
609
+ const deltaY = newest.y - oldest.y;
610
+ newest.time - oldest.time;
611
+
612
+ // Only change direction if significant movement and debounce (300ms between changes)
613
+ const velocityThreshold = 30; // pixels moved in the history window
614
+ const debounceTime = 300;
615
+
616
+ if (Math.abs(deltaY) > velocityThreshold && (now - this._lastDirectionChangeTime) > debounceTime) {
617
+ const newDirection = deltaY < 0; // Moving up = true, moving down = false
618
+ if (newDirection !== this.isPointingUp) {
619
+ this.isPointingUp = newDirection;
620
+ this._lastDirectionChangeTime = now;
621
+ }
602
622
  }
603
623
  }
624
+
604
625
  this.lastTargetY = currentTargetY;
605
626
  }
606
627
 
@@ -1928,14 +1949,17 @@
1928
1949
  pointTo(target, content, direction) {
1929
1950
  const previousTarget = this.targetElement;
1930
1951
 
1952
+ // Determine actual direction ('auto' means will be calculated in updatePosition)
1953
+ const actualDirection = direction || 'auto';
1954
+
1931
1955
  this._emit('beforePointTo', {
1932
1956
  target: Pointy.getTargetElement(target),
1933
1957
  content: content,
1934
- direction: direction,
1958
+ direction: actualDirection,
1935
1959
  fromTarget: previousTarget
1936
1960
  });
1937
1961
 
1938
- // Set manual direction
1962
+ // Set manual direction (null means auto)
1939
1963
  this.manualDirection = direction || null;
1940
1964
 
1941
1965
  // Pause floating animation during movement
@@ -1951,9 +1975,20 @@
1951
1975
  content: content
1952
1976
  });
1953
1977
 
1978
+ this.targetElement = toTarget;
1979
+
1980
+ if (content !== undefined) {
1981
+ this._setMessages(content, false); // false = not from step change, don't auto-start cycle
1982
+ }
1983
+
1984
+ this.updatePosition();
1985
+
1986
+ // Get the resolved direction after updatePosition calculates it
1987
+ const resolvedDirection = this.isPointingUp ? 'up' : 'down';
1988
+
1954
1989
  this.moveTimeout = setTimeout(() => {
1955
1990
  this.container.classList.remove(this.classNames.moving);
1956
- this._emit('pointToComplete', { target: this.targetElement, content: content });
1991
+ this._emit('pointToComplete', { target: this.targetElement, content: content, direction: resolvedDirection });
1957
1992
  this._emit('animationEnd', {
1958
1993
  fromTarget: previousTarget,
1959
1994
  toTarget: this.targetElement,
@@ -1962,15 +1997,7 @@
1962
1997
  });
1963
1998
  }, this.animationDuration);
1964
1999
 
1965
- this.targetElement = toTarget;
1966
-
1967
- if (content !== undefined) {
1968
- this._setMessages(content, false); // false = not from step change, don't auto-start cycle
1969
- }
1970
-
1971
- this.updatePosition();
1972
-
1973
- this._emit('pointTo', { target: this.targetElement, content: content, direction: direction });
2000
+ this._emit('pointTo', { target: this.targetElement, content: content, direction: resolvedDirection });
1974
2001
 
1975
2002
  // Make sure it's visible
1976
2003
  if (!this.isVisible) {
@@ -1,2 +1,2 @@
1
- !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).Pointy=e()}(this,function(){"use strict";class t{static EASINGS={default:"cubic-bezier(0, 0.55, 0.45, 1)",standard:"cubic-bezier(0.4, 0, 0.2, 1)",decelerate:"cubic-bezier(0, 0, 0.2, 1)",accelerate:"cubic-bezier(0.4, 0, 1, 1)",bounce:"cubic-bezier(0.68, -0.55, 0.265, 1.55)",elastic:"cubic-bezier(0.68, -0.6, 0.32, 1.6)",smooth:"cubic-bezier(0.45, 0, 0.55, 1)",snap:"cubic-bezier(0.5, 0, 0.1, 1)","expo-out":"cubic-bezier(0.19, 1, 0.22, 1)","circ-out":"cubic-bezier(0.075, 0.82, 0.165, 1)","back-out":"cubic-bezier(0.175, 0.885, 0.32, 1.275)"};static POINTER_SVG='\n <svg xmlns="http://www.w3.org/2000/svg" width="33" height="33" fill="none" viewBox="0 0 33 33">\n <g filter="url(#pointy-shadow)">\n <path fill="#0a1551" d="m18.65 24.262 6.316-14.905c.467-1.103-.645-2.215-1.748-1.747L8.313 13.925c-1.088.461-1.083 2.004.008 2.459l5.049 2.104c.325.135.583.393.718.718l2.104 5.049c.454 1.09 1.997 1.095 2.458.007"/>\n </g>\n <defs>\n <filter id="pointy-shadow" width="32.576" height="32.575" x="0" y="0" color-interpolation-filters="sRGB" filterUnits="userSpaceOnUse">\n <feFlood flood-opacity="0" result="BackgroundImageFix"/>\n <feColorMatrix in="SourceAlpha" result="hardAlpha" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0"/>\n <feOffset/>\n <feGaussianBlur stdDeviation="3.75"/>\n <feComposite in2="hardAlpha" operator="out"/>\n <feColorMatrix values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.25 0"/>\n <feBlend in2="BackgroundImageFix" result="effect1_dropShadow"/>\n <feBlend in="SourceGraphic" in2="effect1_dropShadow" result="shape"/>\n </filter>\n </defs>\n </svg>\n ';static DEFAULT_CLASS_PREFIX="pointy";static DEFAULT_CLASS_SUFFIXES={container:"container",pointer:"pointer",bubble:"bubble",bubbleText:"bubble-text",hidden:"hidden",visible:"visible",moving:"moving"};static generateClassNames(e=t.DEFAULT_CLASS_PREFIX,s={}){const i={...t.DEFAULT_CLASS_SUFFIXES,...s};return{container:`${e}-${i.container}`,pointer:`${e}-${i.pointer}`,bubble:`${e}-${i.bubble}`,bubbleText:`${e}-${i.bubbleText}`,hidden:`${e}-${i.hidden}`,visible:`${e}-${i.visible}`,moving:`${e}-${i.moving}`}}static DEFAULT_CSS_VAR_PREFIX="pointy";static generateStyles(t,e="pointy"){const s=t,i=e;return`\n @keyframes ${s.container}-float {\n 0%, 100% {\n transform: translateY(0px);\n }\n 50% {\n transform: translateY(-8px);\n }\n }\n\n .${s.container} {\n position: absolute;\n z-index: 9999;\n font-family: 'Circular', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;\n --${i}-duration: 1000ms;\n --${i}-easing: cubic-bezier(0, 0.55, 0.45, 1);\n --${i}-bubble-fade: 500ms;\n transition: left var(--${i}-duration) var(--${i}-easing), top var(--${i}-duration) var(--${i}-easing), opacity 0.3s ease;\n animation: ${s.container}-float 3s ease-in-out infinite;\n }\n\n .${s.container}.${s.moving} {\n animation-play-state: paused;\n }\n\n .${s.container}.${s.hidden} {\n opacity: 0;\n pointer-events: none;\n }\n\n .${s.container}.${s.visible} {\n opacity: 1;\n }\n\n .${s.pointer} {\n width: 33px;\n height: 33px;\n transition: transform var(--${i}-duration) var(--${i}-easing);\n }\n\n .${s.bubble} {\n position: absolute;\n right: 26px;\n top: 0;\n background: #0a1551;\n color: white;\n padding: 4px 12px;\n border-radius: 14px;\n font-size: 14px;\n line-height: 20px;\n font-weight: 400;\n box-shadow: 0 4px 15px rgba(0, 0, 0, 0.25);\n white-space: nowrap;\n overflow: hidden;\n transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1), height 0.5s cubic-bezier(0.4, 0, 0.2, 1), transform var(--${i}-duration) var(--${i}-easing), opacity var(--${i}-bubble-fade) ease;\n }\n\n .${s.bubbleText} {\n display: inline-block;\n }\n `}static injectedStyleKeys=new Set;static injectStyles(e,s="pointy"){const i=JSON.stringify(e)+s;if(t.injectedStyleKeys.has(i))return;if(!t.fontInjected){const e=document.createElement("link");e.href="https://cdn.jotfor.ms/fonts/?family=Circular",e.rel="stylesheet",document.head.appendChild(e),t.fontInjected=!0}const n=document.createElement("style");n.id=`pointy-styles-${i.length}`,n.textContent=t.generateStyles(e,s),document.head.appendChild(n),t.injectedStyleKeys.add(i)}static fontInjected=!1;static getTargetElement(t){return"string"==typeof t?document.querySelector(t):t}static animateText(e,s,i=500,n=null,a=null){const o=.4*i,r=.6*i;let h=null,l=null;if(n){const e=document.createElement("div");e.style.cssText="visibility: hidden; position: absolute; padding: 4px 12px;",t.renderContent(e,s),n.appendChild(e),h=e.offsetWidth,l=e.offsetHeight,n.removeChild(e);const i=n.offsetWidth,a=n.offsetHeight;n.style.width=i+"px",n.style.height=a+"px"}e.style.transition=`clip-path ${o}ms ease-in`,e.style.clipPath="inset(0 0 0 100%)",setTimeout(()=>{t.renderContent(e,s),n&&null!==h&&(n.style.width=h+"px",n.style.height=l+"px"),e.style.transition="none",e.style.clipPath="inset(0 100% 0 0)",e.offsetHeight,e.style.transition=`clip-path ${r}ms ease-out`,e.style.clipPath="inset(0 0 0 0)",n&&setTimeout(()=>{n.style.width="",n.style.height=""},r+100),a&&a()},o)}static renderContent(t,e){if(e&&"object"==typeof e&&e.$$typeof)if("undefined"!=typeof ReactDOM&&ReactDOM.createRoot){const s=ReactDOM.createRoot(t);s.render(e),t._reactRoot=s}else"undefined"!=typeof ReactDOM&&ReactDOM.render?ReactDOM.render(e,t):(console.warn("Pointy: React element passed but ReactDOM not found"),t.innerHTML=String(e));else t.innerHTML=e}constructor(e={}){if(this.classPrefix=e.classPrefix||t.DEFAULT_CLASS_PREFIX,this.classNames=t.generateClassNames(this.classPrefix,e.classSuffixes),e.classNames&&(this.classNames={...this.classNames,...e.classNames}),this.cssVarPrefix=e.cssVarPrefix||this.classPrefix,this.pointerSvg=e.pointerSvg||t.POINTER_SVG,t.injectStyles(this.classNames,this.cssVarPrefix),this.steps=e.steps||[],this.offsetX=void 0!==e.offsetX?e.offsetX:20,this.offsetY=void 0!==e.offsetY?e.offsetY:16,this.tracking=void 0===e.tracking||e.tracking,this.trackingFps=void 0!==e.trackingFps?e.trackingFps:60,this.animationDuration=void 0!==e.animationDuration?e.animationDuration:1e3,this.introFadeDuration=void 0!==e.introFadeDuration?e.introFadeDuration:1e3,this.bubbleFadeDuration=void 0!==e.bubbleFadeDuration?e.bubbleFadeDuration:500,this.messageTransitionDuration=void 0!==e.messageTransitionDuration?e.messageTransitionDuration:500,this.easing=void 0!==e.easing?e.easing:"default",this.resetOnComplete=void 0===e.resetOnComplete||e.resetOnComplete,this.floatingAnimation=void 0===e.floatingAnimation||e.floatingAnimation,this.initialPosition=e.initialPosition||"center",this.initialPositionOffset=void 0!==e.initialPositionOffset?e.initialPositionOffset:32,this.resetPositionOnHide=void 0!==e.resetPositionOnHide&&e.resetPositionOnHide,this.autoplay=e.autoplay||null,this.autoplayEnabled=void 0!==e.autoplayEnabled&&e.autoplayEnabled,this.autoplayWaitForMessages=void 0===e.autoplayWaitForMessages||e.autoplayWaitForMessages,this.hideOnComplete=void 0===e.hideOnComplete||e.hideOnComplete,this.hideOnCompleteDelay=void 0!==e.hideOnCompleteDelay?e.hideOnCompleteDelay:null,this._autoplayTimeoutId=null,this._autoplayPaused=!1,this._messagesCompletedForStep=!1,this._hideOnCompleteTimeoutId=null,this.onStepChange=e.onStepChange,this.onComplete=e.onComplete,this._eventListeners={},this.targetElement=e.target?t.getTargetElement(e.target):null,this.currentStepIndex=0,this.currentMessageIndex=0,this.currentMessages=[],this.messageInterval=e.messageInterval||null,this._messageIntervalId=null,this.isVisible=!1,this.isPointingUp=!0,this.lastTargetY=null,this.manualDirection=null,this.moveTimeout=null,this._hasShownBefore=!1,this.steps.length>0&&(this.targetElement=t.getTargetElement(this.steps[0].target)),this.container=document.createElement("div"),this.container.className=`${this.classNames.container} ${this.classNames.hidden}`,this.container.style.setProperty(`--${this.cssVarPrefix}-duration`,`${this.animationDuration}ms`),this.container.style.setProperty(`--${this.cssVarPrefix}-easing`,this._resolveEasing(this.easing)),this.container.style.setProperty(`--${this.cssVarPrefix}-bubble-fade`,`${this.bubbleFadeDuration}ms`),this.floatingAnimation||(this.container.style.animationPlayState="paused"),this.pointer=document.createElement("div"),this.pointer.className=this.classNames.pointer,t.renderContent(this.pointer,this.pointerSvg),this.bubble=document.createElement("div"),this.bubble.className=this.classNames.bubble,this.bubbleText=document.createElement("span"),this.bubbleText.className=this.classNames.bubbleText,this.steps.length>0){const e=this.steps[0].content;this.currentMessages=Array.isArray(e)?e:[e],t.renderContent(this.bubbleText,this.currentMessages[0])}else{const s=e.content||"";this.currentMessages=Array.isArray(s)?s:[s],t.renderContent(this.bubbleText,this.currentMessages[0])}this.currentMessageIndex=0,this.bubble.appendChild(this.bubbleText),this.container.appendChild(this.pointer),this.container.appendChild(this.bubble),this.updatePosition=this.updatePosition.bind(this),this._trackPosition=this._trackPosition.bind(this),this._lastTrackTime=0,window.addEventListener("resize",this.updatePosition),window.addEventListener("scroll",this.updatePosition)}_trackPosition(){if(this.isVisible&&this.targetElement){if(this.trackingFps>0){const t=performance.now(),e=1e3/this.trackingFps;t-this._lastTrackTime>=e&&(this._lastTrackTime=t,this.updatePosition(),this._emit("track",{target:this.targetElement,timestamp:t}))}else this.updatePosition(),this._emit("track",{target:this.targetElement,timestamp:performance.now()});this._rafId=requestAnimationFrame(this._trackPosition)}else this._rafId=null}_startTracking(){this.tracking&&(this._rafId||this._trackPosition())}_stopTracking(){this._rafId&&(cancelAnimationFrame(this._rafId),this._rafId=null)}updatePosition(){if(!this.targetElement)return;const t=this.targetElement.getBoundingClientRect(),e=window.scrollX,s=window.scrollY;if(null!==this.manualDirection)this.isPointingUp="up"===this.manualDirection;else{const e=t.top+s;if(null!==this.lastTargetY){const t=50;e<this.lastTargetY-t?this.isPointingUp=!0:e>this.lastTargetY+t&&(this.isPointingUp=!1)}this.lastTargetY=e}let i,n;if(this.isPointingUp)this.pointer.style.transform="rotate(0deg)",i=t.left+e-25+this.offsetX,n=t.bottom+s-8-this.offsetY,this.bubble.style.transform="translateY(28px)";else{this.pointer.style.transform="rotate(90deg)",i=t.left+e-25+this.offsetX,n=t.top+s-25+this.offsetY;const a=this.bubble.offsetHeight||28;this.bubble.style.transform=`translateY(-${a}px)`}this.container.style.left=`${i}px`,this.container.style.top=`${n}px`}show(){if(this._emit("beforeShow",{target:this.targetElement}),this._hideOnCompleteTimeoutId&&(clearTimeout(this._hideOnCompleteTimeoutId),this._hideOnCompleteTimeoutId=null),document.body.contains(this.container)||document.body.appendChild(this.container),!this._hasShownBefore){this._hasShownBefore=!0;const t="first-step"===this.initialPosition,e=this._getInitialPosition(),s=e.x,i=e.y;if(this.container.style.transition=`opacity ${this.introFadeDuration}ms ease`,this.pointer.style.transition="none",this.bubble.style.transition="none",this.bubble.style.opacity="0",this.container.style.left=`${s}px`,this.container.style.top=`${i}px`,t&&void 0!==e.isPointingUp)if(this.isPointingUp=e.isPointingUp,this.isPointingUp)this.pointer.style.transform="rotate(0deg)",this.bubble.style.transform="translateY(28px)";else{this.pointer.style.transform="rotate(90deg)";const t=this.bubble.offsetHeight||28;this.bubble.style.transform=`translateY(-${t}px)`}else this.pointer.style.transform="rotate(0deg)",this.bubble.style.transform="translateY(0)";return this.container.style.display="flex",this.container.offsetHeight,this.container.classList.remove(this.classNames.hidden),this.container.classList.add(this.classNames.visible),this.isVisible=!0,this._emit("introAnimationStart",{duration:this.introFadeDuration,initialPosition:{x:s,y:i}}),void setTimeout(()=>{this._emit("introAnimationEnd",{initialPosition:{x:s,y:i}}),t?(this.container.style.transition="none",this.pointer.style.transition="none",this._startTracking(),this.bubble.style.transition=`opacity ${this.bubbleFadeDuration}ms ease`,this.bubble.style.opacity="1",setTimeout(()=>{this.container.style.transition="",this.pointer.style.transition="",this.bubble.style.transition=""},this.bubbleFadeDuration),this.messageInterval&&this.currentMessages.length>1&&!this._messageIntervalId&&this._startMessageCycle(),this._scheduleAutoplay(),this._emit("show",{target:this.targetElement,isIntro:!0,isFirstStep:!0})):(this.container.style.transition="",this.pointer.style.transition="",this.bubble.style.transition="none",this.updatePosition(),this._startTracking(),setTimeout(()=>{this.bubble.style.transition="",this.bubble.style.opacity="1",this.messageInterval&&this.currentMessages.length>1&&!this._messageIntervalId&&this._startMessageCycle(),this._scheduleAutoplay()},this.animationDuration),this._emit("show",{target:this.targetElement,isIntro:!0,isFirstStep:!1}))},this.introFadeDuration)}this.container.style.display="flex",this.container.offsetHeight,this.container.classList.remove(this.classNames.hidden),this.container.classList.add(this.classNames.visible),this.isVisible=!0,this.updatePosition(),this._startTracking(),this._messageCyclePausedByHide&&this.messageInterval&&this.currentMessages.length>1?(this._startMessageCycle(),this._messageCyclePausedByHide=!1):this.messageInterval&&this.currentMessages.length>1&&!this._messageIntervalId&&this._startMessageCycle(),this._wasAutoplayActiveBeforeHide&&(this._scheduleAutoplay(),this._wasAutoplayActiveBeforeHide=!1),this._emit("show",{target:this.targetElement,isIntro:!1})}hide(){this._emit("beforeHide",{target:this.targetElement}),this.container.classList.remove(this.classNames.visible),this.container.classList.add(this.classNames.hidden),this.isVisible=!1,this.resetPositionOnHide&&(this._hasShownBefore=!1),this._stopTracking(),this._messageIntervalId&&(this._stopMessageCycle(),this._messageCyclePausedByHide=!0),this._wasAutoplayActiveBeforeHide=this.autoplay&&this.autoplayEnabled&&!this._autoplayPaused,this._stopAutoplay(),this._emit("hide",{target:this.targetElement})}restart(){this._emit("beforeRestart",{}),this._hasShownBefore=!1,this.isVisible?(this.container.classList.remove(this.classNames.visible),this.container.classList.add(this.classNames.hidden),this._stopTracking(),this._stopMessageCycle(),this.isVisible=!1,setTimeout(()=>{this.goToStep(0),this.show(),this._emit("restart",{})},50)):(this.goToStep(0),this.show(),this._emit("restart",{}))}destroy(){this._emit("destroy",{}),document.body.contains(this.container)&&document.body.removeChild(this.container),window.removeEventListener("resize",this.updatePosition),window.removeEventListener("scroll",this.updatePosition),this._stopTracking(),this._hideOnCompleteTimeoutId&&(clearTimeout(this._hideOnCompleteTimeoutId),this._hideOnCompleteTimeoutId=null),this._eventListeners={}}reset(e=!0){this._emit("beforeReset",{currentStep:this.currentStepIndex}),this._stopMessageCycle(),this._hideOnCompleteTimeoutId&&(clearTimeout(this._hideOnCompleteTimeoutId),this._hideOnCompleteTimeoutId=null),this.container.classList.add(this.classNames.moving),this.moveTimeout&&clearTimeout(this.moveTimeout);const{x:s,y:i}=this._getInitialPosition();if(this.container.style.left=`${s}px`,this.container.style.top=`${i}px`,this.bubble.style.opacity="0",e&&this.steps.length>0){this.currentStepIndex=0;const e=this.steps[0];this.targetElement=t.getTargetElement(e.target),this.currentMessages=Array.isArray(e.content)?e.content:[e.content],this.currentMessageIndex=0,t.renderContent(this.bubbleText,this.currentMessages[0])}this.moveTimeout=setTimeout(()=>{this.container.classList.remove(this.classNames.moving),this._hasShownBefore=!1,this._emit("reset",{stepIndex:this.currentStepIndex})},this.animationDuration)}setResetOnComplete(t){const e=this.resetOnComplete;e!==t&&(this.resetOnComplete=t,this._emit("resetOnCompleteChange",{from:e,to:t}))}setFloatingAnimation(t){const e=this.floatingAnimation;e!==t&&(this.floatingAnimation=t,this.container.style.animationPlayState=t?"":"paused",this._emit("floatingAnimationChange",{from:e,to:t}))}isFloatingAnimationEnabled(){return this.floatingAnimation}setTracking(t){const e=this.tracking;e!==t&&(this.tracking=t,t&&this.isVisible?this._startTracking():t||this._stopTracking(),this._emit("trackingChange",{from:e,to:t}))}setTrackingFps(t){const e=this.trackingFps;e!==t&&(this.trackingFps=t,this._emit("trackingFpsChange",{from:e,to:t}))}isTrackingEnabled(){return this.tracking}updateContent(e,s=!0){"string"==typeof e&&this.bubbleText.innerHTML===e||(s?t.animateText(this.bubbleText,e,this.messageTransitionDuration,this.bubble,()=>{this.updatePosition()}):(t.renderContent(this.bubbleText,e),this.updatePosition()))}_setMessages(t,e=!1){const s=null!==this._messageIntervalId;this._stopMessageCycle(),this.currentMessages=Array.isArray(t)?t:[t],this.currentMessageIndex=0,this.updateContent(this.currentMessages[0]),e&&this.messageInterval&&this.currentMessages.length>1?this._startMessageCycle():s&&this.currentMessages.length>1&&(this._messageCyclePaused=!0),this._emit("messagesSet",{messages:this.currentMessages,total:this.currentMessages.length,cyclePaused:!0===this._messageCyclePaused})}_startMessageCycle(){this._messagesCompletedForStep=!1,this._messageIntervalId=setInterval(()=>{this.currentMessageIndex===this.currentMessages.length-1&&this.autoplay&&this.autoplayWaitForMessages?(this._stopMessageCycle(),this._messagesCompletedForStep=!0,this._emit("messageCycleComplete",{stepIndex:this.currentStepIndex,totalMessages:this.currentMessages.length}),this._scheduleAutoplayAfterMessages()):this.nextMessage(!0)},this.messageInterval),this._emit("messageCycleStart",{interval:this.messageInterval,totalMessages:this.currentMessages.length})}_stopMessageCycle(){this._messageIntervalId&&(clearInterval(this._messageIntervalId),this._messageIntervalId=null,this._emit("messageCycleStop",{currentIndex:this.currentMessageIndex}))}pauseMessageCycle(){this._messageIntervalId&&(clearInterval(this._messageIntervalId),this._messageIntervalId=null,this._messageCyclePaused=!0,this._emit("messageCyclePause",{currentIndex:this.currentMessageIndex}))}resumeMessageCycle(){return!!(this._messageCyclePaused&&this.messageInterval&&this.currentMessages.length>1)&&(this._messageCyclePaused=!1,this._startMessageCycle(),this._emit("messageCycleResume",{currentIndex:this.currentMessageIndex}),!0)}startMessageCycle(t){return!this._messageIntervalId&&(!(this.currentMessages.length<=1)&&(void 0!==t&&(this.messageInterval=t),!!this.messageInterval&&(this._messageCyclePaused=!1,this._startMessageCycle(),!0)))}stopMessageCycle(){return!!this._messageIntervalId&&(this._stopMessageCycle(),this._messageCyclePaused=!1,!0)}isMessageCycleActive(){return null!==this._messageIntervalId}isMessageCyclePaused(){return!0===this._messageCyclePaused}nextMessage(t=!1){if(this.currentMessages.length<=1)return!1;const e=this.currentMessageIndex;return this.currentMessageIndex=(this.currentMessageIndex+1)%this.currentMessages.length,this.updateContent(this.currentMessages[this.currentMessageIndex]),this._emit("messageChange",{fromIndex:e,toIndex:this.currentMessageIndex,message:this.currentMessages[this.currentMessageIndex],total:this.currentMessages.length,isAuto:t}),!0}prevMessage(){if(this.currentMessages.length<=1)return!1;const t=this.currentMessageIndex;return this.currentMessageIndex=(this.currentMessageIndex-1+this.currentMessages.length)%this.currentMessages.length,this.updateContent(this.currentMessages[this.currentMessageIndex]),this._emit("messageChange",{fromIndex:t,toIndex:this.currentMessageIndex,message:this.currentMessages[this.currentMessageIndex],total:this.currentMessages.length}),!0}goToMessage(t){if(t<0||t>=this.currentMessages.length)return;const e=this.currentMessageIndex;this.currentMessageIndex=t,this.updateContent(this.currentMessages[this.currentMessageIndex]),this._emit("messageChange",{fromIndex:e,toIndex:this.currentMessageIndex,message:this.currentMessages[this.currentMessageIndex],total:this.currentMessages.length})}getCurrentMessage(){return this.currentMessageIndex}getTotalMessages(){return this.currentMessages.length}setContent(e,s=!0){const i=null!==this._messageIntervalId;s?this._setMessages(e,!1):(this._stopMessageCycle(),this.currentMessages=Array.isArray(e)?e:[e],this.currentMessageIndex=0,t.renderContent(this.bubbleText,this.currentMessages[0]),this.updatePosition(),i&&this.currentMessages.length>1&&(this._messageCyclePaused=!0)),this._emit("contentSet",{messages:this.currentMessages,total:this.currentMessages.length,animated:s,cyclePaused:!0===this._messageCyclePaused})}setMessageInterval(t){const e=this.messageInterval;e!==t&&(this.messageInterval=t,this._stopMessageCycle(),t&&this.currentMessages.length>1&&this._startMessageCycle(),this._emit("messageIntervalChange",{from:e,to:t}))}updateTarget(e){const s=this.targetElement;this.targetElement=t.getTargetElement(e),this.updatePosition(),this._emit("targetChange",{from:s,to:this.targetElement})}setOffset(t,e){const s=this.offsetX,i=this.offsetY;s===t&&i===e||(this.offsetX=t,this.offsetY=e,this.updatePosition(),this._emit("offsetChange",{from:{x:s,y:i},to:{x:t,y:e}}))}setAnimationDuration(t){const e=this.animationDuration;e!==t&&(this.animationDuration=t,this.container.style.setProperty(`--${this.cssVarPrefix}-duration`,`${t}ms`),this._emit("animationDurationChange",{from:e,to:t}))}setIntroFadeDuration(t){const e=this.introFadeDuration;e!==t&&(this.introFadeDuration=t,this._emit("introFadeDurationChange",{from:e,to:t}))}setBubbleFadeDuration(t){const e=this.bubbleFadeDuration;e!==t&&(this.bubbleFadeDuration=t,this.container.style.setProperty(`--${this.cssVarPrefix}-bubble-fade`,`${t}ms`),this._emit("bubbleFadeDurationChange",{from:e,to:t}))}_getInitialPosition(){const e=this.initialPositionOffset,s=window.innerWidth,i=window.innerHeight;if("first-step"===this.initialPosition&&this.steps.length>0){const e=this.steps[0],s=t.getTargetElement(e.target);if(s){const t=s.getBoundingClientRect(),i=window.scrollX,n=window.scrollY,a="down"!==e.direction;let o,r;return a?(o=t.left+i-25+this.offsetX,r=t.bottom+n-8-this.offsetY):(o=t.left+i-25+this.offsetX,r=t.top+n-25+this.offsetY),{x:o,y:r,isPointingUp:a}}}if(this.initialPosition&&"string"!=typeof this.initialPosition){const t=this.initialPosition.getBoundingClientRect();return{x:t.left+t.width/2,y:t.top+t.height/2}}if("string"==typeof this.initialPosition&&(this.initialPosition.startsWith("#")||this.initialPosition.startsWith("."))){const t=document.querySelector(this.initialPosition);if(t){const e=t.getBoundingClientRect();return{x:e.left+e.width/2,y:e.top+e.height/2}}}const n={center:{x:s/2,y:i/2},"top-left":{x:e,y:e},"top-center":{x:s/2,y:e},"top-right":{x:s-e,y:e},"middle-left":{x:e,y:i/2},"middle-right":{x:s-e,y:i/2},"bottom-left":{x:e,y:i-e},"bottom-center":{x:s/2,y:i-e},"bottom-right":{x:s-e,y:i-e}};return n[this.initialPosition]||n.center}setInitialPosition(t){const e=["center","top-left","top-center","top-right","middle-left","middle-right","bottom-left","bottom-center","bottom-right","first-step"];if("string"==typeof t&&!t.startsWith("#")&&!t.startsWith(".")&&!e.includes(t))return void console.warn(`Invalid initial position: ${t}. Valid presets: ${e.join(", ")}. Or use a CSS selector or DOM element.`);const s=this.initialPosition;s!==t&&(this.initialPosition=t,this._emit("initialPositionChange",{from:s,to:t}))}animateToInitialPosition(){if(!this.isVisible)return;const{x:t,y:e}=this._getInitialPosition();this._stopTracking(),this.container.style.cssText=`\n position: fixed;\n left: ${t}px;\n top: ${e}px;\n opacity: 0;\n transition: none;\n `,this.bubble.style.opacity="0",this.bubble.style.transition="none",this.container.offsetHeight,this.container.style.transition=`opacity ${this.introFadeDuration}ms ease`,this.container.style.opacity="1",setTimeout(()=>{this.container.style.transition="",this.container.style.cssText="",this.container.style.left=`${t}px`,this.container.style.top=`${e}px`,this.container.offsetHeight,this.updatePosition(),this._startTracking(),setTimeout(()=>{this.bubble.style.transition="",this.bubble.style.opacity="1"},this.animationDuration)},this.introFadeDuration)}setInitialPositionOffset(t){const e=this.initialPositionOffset;e!==t&&(this.initialPositionOffset=t,this._emit("initialPositionOffsetChange",{from:e,to:t}))}_resolveEasing(e){return t.EASINGS[e]?t.EASINGS[e]:e}setEasing(t){const e=this.easing;e!==t&&(this.easing=t,this.container.style.setProperty(`--${this.cssVarPrefix}-easing`,this._resolveEasing(t)),this._emit("easingChange",{from:e,to:t}))}setMessageTransitionDuration(t){const e=this.messageTransitionDuration;e!==t&&(this.messageTransitionDuration=t,this._emit("messageTransitionDurationChange",{from:e,to:t}))}setPointerSvg(e){const s=this.pointerSvg;s!==e&&(this.pointerSvg=e,t.renderContent(this.pointer,e),this._emit("pointerSvgChange",{from:s,to:e}))}getPointerSvg(){return this.pointerSvg}getClassNames(){return{...this.classNames}}getClassPrefix(){return this.classPrefix}getCssVarPrefix(){return this.cssVarPrefix}static getEasingPresets(){return Object.keys(t.EASINGS)}static getInitialPositions(){return["center","top-left","top-center","top-right","middle-left","middle-right","bottom-left","bottom-center","bottom-right","first-step"]}goToStep(e){if(0===this.steps.length||e<0||e>=this.steps.length)return;this._stopAutoplay(),this._messagesCompletedForStep=!1;const s=this.currentStepIndex,i=this.targetElement;this.currentStepIndex=e;const n=this.steps[this.currentStepIndex];this._emit("beforeStepChange",{fromIndex:s,toIndex:e,step:n,fromTarget:i}),this.manualDirection=n.direction||null,this.container.classList.add(this.classNames.moving),this.moveTimeout&&clearTimeout(this.moveTimeout),this._emit("animationStart",{fromTarget:i,toTarget:t.getTargetElement(n.target),type:"step",stepIndex:e}),this.moveTimeout=setTimeout(()=>{this.container.classList.remove(this.classNames.moving),this._emit("moveComplete",{index:e,step:n,target:this.targetElement}),this._emit("animationEnd",{fromTarget:i,toTarget:this.targetElement,type:"step",stepIndex:e}),this._scheduleAutoplay()},this.animationDuration),this._emit("move",{index:e,step:n}),this._setMessages(n.content,!0),this.targetElement=t.getTargetElement(n.target),this.updatePosition(),this._emit("stepChange",{fromIndex:s,toIndex:e,step:n,target:this.targetElement}),this.onStepChange&&this.onStepChange(this.currentStepIndex,n)}_scheduleAutoplay(){if(!this.autoplay||!this.autoplayEnabled||this._autoplayPaused||!this.isVisible)return;const t=this.steps[this.currentStepIndex],e=this.currentMessages.length>1&&this.messageInterval;if(this.autoplayWaitForMessages&&e)return;const s=void 0!==t.duration?t.duration:this.autoplay;s&&s>0&&(this._autoplayTimeoutId=setTimeout(()=>{!this._autoplayPaused&&this.isVisible&&this.autoplayEnabled&&(this._emit("autoplayNext",{fromIndex:this.currentStepIndex,duration:s}),this.next())},s))}_scheduleAutoplayAfterMessages(){if(!this.autoplay||!this.autoplayEnabled||this._autoplayPaused||!this.isVisible)return;this._autoplayTimeoutId=setTimeout(()=>{!this._autoplayPaused&&this.isVisible&&this._messagesCompletedForStep&&(this._emit("autoplayNext",{fromIndex:this.currentStepIndex,afterMessages:!0}),this.next())},300)}_stopAutoplay(){this._autoplayTimeoutId&&(clearTimeout(this._autoplayTimeoutId),this._autoplayTimeoutId=null)}startAutoplay(){this.autoplay&&(this.autoplayEnabled=!0,this._autoplayPaused=!1,this._emit("autoplayStart",{}),this._scheduleAutoplay())}stopAutoplay(){this._stopAutoplay(),this.autoplayEnabled=!1,this._autoplayPaused=!1,this._emit("autoplayStop",{})}pauseAutoplay(){this._stopAutoplay(),this._autoplayPaused=!0,this._emit("autoplayPause",{})}resumeAutoplay(){this._autoplayPaused&&(this._autoplayPaused=!1,this._emit("autoplayResume",{}),this._scheduleAutoplay())}isAutoplayActive(){return this.autoplay&&this.autoplayEnabled&&!this._autoplayPaused}isAutoplayPaused(){return this._autoplayPaused}setAutoplayInterval(t){const e=this.autoplay;e!==t&&(this.autoplay=t,this._emit("autoplayChange",{from:e,to:t}),this.autoplayEnabled&&t&&this.isVisible?(this._stopAutoplay(),this._scheduleAutoplay()):t||(this._stopAutoplay(),this.autoplayEnabled=!1))}setAutoplay(t){this.setAutoplayInterval(t),t&&this.isVisible&&(this.autoplayEnabled=!0,this._autoplayPaused=!1,this.restart())}setAutoplayWaitForMessages(t){const e=this.autoplayWaitForMessages;e!==t&&(this.autoplayWaitForMessages=t,this._emit("autoplayWaitForMessagesChange",{from:e,to:t}))}setHideOnComplete(t){const e=this.hideOnComplete;e!==t&&(this.hideOnComplete=t,this._emit("hideOnCompleteChange",{from:e,to:t}))}setHideOnCompleteDelay(t){const e=this.hideOnCompleteDelay;e!==t&&(this.hideOnCompleteDelay=t,this._emit("hideOnCompleteDelayChange",{from:e,to:t}))}next(){if(0!==this.steps.length)if(this.currentStepIndex<this.steps.length-1)this._emit("next",{fromIndex:this.currentStepIndex,toIndex:this.currentStepIndex+1}),this.goToStep(this.currentStepIndex+1);else{const t=this.autoplay&&this.autoplayEnabled&&!this._autoplayPaused;if(this._emit("complete",{totalSteps:this.steps.length,source:t?"autoplay":"manual"}),t&&(this._stopAutoplay(),this.autoplayEnabled=!1,this._emit("autoplayComplete",{totalSteps:this.steps.length})),this.resetOnComplete){if(this.reset(),this.hideOnComplete){const e=null!==this.hideOnCompleteDelay?this.hideOnCompleteDelay:this.animationDuration,s=t?"autoplay":"manual";this._hideOnCompleteTimeoutId=setTimeout(()=>{this.hide(),this._emit("autoHide",{delay:e,source:s})},this.animationDuration+e)}}else if(this.hideOnComplete){const e=null!==this.hideOnCompleteDelay?this.hideOnCompleteDelay:this.animationDuration,s=t?"autoplay":"manual";this._hideOnCompleteTimeoutId=setTimeout(()=>{this.hide(),this._emit("autoHide",{delay:e,source:s})},e)}this.onComplete&&this.onComplete()}}prev(){0!==this.steps.length&&this.currentStepIndex>0&&(this._emit("prev",{fromIndex:this.currentStepIndex,toIndex:this.currentStepIndex-1}),this.goToStep(this.currentStepIndex-1))}getCurrentStep(){return this.currentStepIndex}getTotalSteps(){return this.steps.length}pointTo(e,s,i){const n=this.targetElement;this._emit("beforePointTo",{target:t.getTargetElement(e),content:s,direction:i,fromTarget:n}),this.manualDirection=i||null,this.container.classList.add(this.classNames.moving),this.moveTimeout&&clearTimeout(this.moveTimeout);const a=t.getTargetElement(e);this._emit("animationStart",{fromTarget:n,toTarget:a,type:"pointTo",content:s}),this.moveTimeout=setTimeout(()=>{this.container.classList.remove(this.classNames.moving),this._emit("pointToComplete",{target:this.targetElement,content:s}),this._emit("animationEnd",{fromTarget:n,toTarget:this.targetElement,type:"pointTo",content:s})},this.animationDuration),this.targetElement=a,void 0!==s&&this._setMessages(s,!1),this.updatePosition(),this._emit("pointTo",{target:this.targetElement,content:s,direction:i}),this.isVisible||this.show()}on(t,e){return this._eventListeners[t]||(this._eventListeners[t]=[]),this._eventListeners[t].push(e),this}off(t,e){return this._eventListeners[t]?(e?this._eventListeners[t]=this._eventListeners[t].filter(t=>t!==e):delete this._eventListeners[t],this):this}_emit(e,s){const i={...s,type:e,pointy:this};this._eventListeners[e]&&this._eventListeners[e].forEach(t=>{try{t(i)}catch(t){console.error(`Pointy: Error in ${e} event handler:`,t)}});const n=t.getEventGroup(e);n&&this._eventListeners[n]&&this._eventListeners[n].forEach(t=>{try{t(i)}catch(t){console.error(`Pointy: Error in ${n} group handler for ${e}:`,t)}}),["*","all"].forEach(t=>{this._eventListeners[t]&&this._eventListeners[t].forEach(t=>{try{t(i)}catch(t){console.error(`Pointy: Error in wildcard handler for ${e}:`,t)}})})}static getEventGroup(e){for(const[s,i]of Object.entries(t.EVENT_GROUPS))if(i.includes(e))return s;return e.endsWith("Change")?"config":null}static getEventsInGroup(e){return t.EVENT_GROUPS[e]||[]}}return t.EVENT_GROUPS={lifecycle:["beforeShow","show","beforeHide","hide","destroy","beforeRestart","restart","beforeReset","reset"],navigation:["beforeStepChange","stepChange","next","prev","complete"],animation:["animationStart","animationEnd","move","moveComplete","introAnimationStart","introAnimationEnd"],content:["contentSet","messagesSet","messageChange"],messageCycle:["messageCycleStart","messageCycleStop","messageCyclePause","messageCycleResume","messageCycleComplete"],pointing:["beforePointTo","pointTo","pointToComplete"],tracking:["track","targetChange","trackingChange","trackingFpsChange"],autoplay:["autoplayStart","autoplayStop","autoplayPause","autoplayResume","autoplayNext","autoplayComplete","autoHide","autoplayChange","autoplayWaitForMessagesChange"]},t});
1
+ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).Pointy=e()}(this,function(){"use strict";class t{static EASINGS={default:"cubic-bezier(0, 0.55, 0.45, 1)",standard:"cubic-bezier(0.4, 0, 0.2, 1)",decelerate:"cubic-bezier(0, 0, 0.2, 1)",accelerate:"cubic-bezier(0.4, 0, 1, 1)",bounce:"cubic-bezier(0.68, -0.55, 0.265, 1.55)",elastic:"cubic-bezier(0.68, -0.6, 0.32, 1.6)",smooth:"cubic-bezier(0.45, 0, 0.55, 1)",snap:"cubic-bezier(0.5, 0, 0.1, 1)","expo-out":"cubic-bezier(0.19, 1, 0.22, 1)","circ-out":"cubic-bezier(0.075, 0.82, 0.165, 1)","back-out":"cubic-bezier(0.175, 0.885, 0.32, 1.275)"};static POINTER_SVG='\n <svg xmlns="http://www.w3.org/2000/svg" width="33" height="33" fill="none" viewBox="0 0 33 33">\n <g filter="url(#pointy-shadow)">\n <path fill="#0a1551" d="m18.65 24.262 6.316-14.905c.467-1.103-.645-2.215-1.748-1.747L8.313 13.925c-1.088.461-1.083 2.004.008 2.459l5.049 2.104c.325.135.583.393.718.718l2.104 5.049c.454 1.09 1.997 1.095 2.458.007"/>\n </g>\n <defs>\n <filter id="pointy-shadow" width="32.576" height="32.575" x="0" y="0" color-interpolation-filters="sRGB" filterUnits="userSpaceOnUse">\n <feFlood flood-opacity="0" result="BackgroundImageFix"/>\n <feColorMatrix in="SourceAlpha" result="hardAlpha" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0"/>\n <feOffset/>\n <feGaussianBlur stdDeviation="3.75"/>\n <feComposite in2="hardAlpha" operator="out"/>\n <feColorMatrix values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.25 0"/>\n <feBlend in2="BackgroundImageFix" result="effect1_dropShadow"/>\n <feBlend in="SourceGraphic" in2="effect1_dropShadow" result="shape"/>\n </filter>\n </defs>\n </svg>\n ';static DEFAULT_CLASS_PREFIX="pointy";static DEFAULT_CLASS_SUFFIXES={container:"container",pointer:"pointer",bubble:"bubble",bubbleText:"bubble-text",hidden:"hidden",visible:"visible",moving:"moving"};static generateClassNames(e=t.DEFAULT_CLASS_PREFIX,s={}){const i={...t.DEFAULT_CLASS_SUFFIXES,...s};return{container:`${e}-${i.container}`,pointer:`${e}-${i.pointer}`,bubble:`${e}-${i.bubble}`,bubbleText:`${e}-${i.bubbleText}`,hidden:`${e}-${i.hidden}`,visible:`${e}-${i.visible}`,moving:`${e}-${i.moving}`}}static DEFAULT_CSS_VAR_PREFIX="pointy";static generateStyles(t,e="pointy"){const s=t,i=e;return`\n @keyframes ${s.container}-float {\n 0%, 100% {\n transform: translateY(0px);\n }\n 50% {\n transform: translateY(-8px);\n }\n }\n\n .${s.container} {\n position: absolute;\n z-index: 9999;\n font-family: 'Circular', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;\n --${i}-duration: 1000ms;\n --${i}-easing: cubic-bezier(0, 0.55, 0.45, 1);\n --${i}-bubble-fade: 500ms;\n transition: left var(--${i}-duration) var(--${i}-easing), top var(--${i}-duration) var(--${i}-easing), opacity 0.3s ease;\n animation: ${s.container}-float 3s ease-in-out infinite;\n }\n\n .${s.container}.${s.moving} {\n animation-play-state: paused;\n }\n\n .${s.container}.${s.hidden} {\n opacity: 0;\n pointer-events: none;\n }\n\n .${s.container}.${s.visible} {\n opacity: 1;\n }\n\n .${s.pointer} {\n width: 33px;\n height: 33px;\n transition: transform var(--${i}-duration) var(--${i}-easing);\n }\n\n .${s.bubble} {\n position: absolute;\n right: 26px;\n top: 0;\n background: #0a1551;\n color: white;\n padding: 4px 12px;\n border-radius: 14px;\n font-size: 14px;\n line-height: 20px;\n font-weight: 400;\n box-shadow: 0 4px 15px rgba(0, 0, 0, 0.25);\n white-space: nowrap;\n overflow: hidden;\n transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1), height 0.5s cubic-bezier(0.4, 0, 0.2, 1), transform var(--${i}-duration) var(--${i}-easing), opacity var(--${i}-bubble-fade) ease;\n }\n\n .${s.bubbleText} {\n display: inline-block;\n }\n `}static injectedStyleKeys=new Set;static injectStyles(e,s="pointy"){const i=JSON.stringify(e)+s;if(t.injectedStyleKeys.has(i))return;if(!t.fontInjected){const e=document.createElement("link");e.href="https://cdn.jotfor.ms/fonts/?family=Circular",e.rel="stylesheet",document.head.appendChild(e),t.fontInjected=!0}const n=document.createElement("style");n.id=`pointy-styles-${i.length}`,n.textContent=t.generateStyles(e,s),document.head.appendChild(n),t.injectedStyleKeys.add(i)}static fontInjected=!1;static getTargetElement(t){return"string"==typeof t?document.querySelector(t):t}static animateText(e,s,i=500,n=null,a=null){const o=.4*i,r=.6*i;let h=null,l=null;if(n){const e=document.createElement("div");e.style.cssText="visibility: hidden; position: absolute; padding: 4px 12px;",t.renderContent(e,s),n.appendChild(e),h=e.offsetWidth,l=e.offsetHeight,n.removeChild(e);const i=n.offsetWidth,a=n.offsetHeight;n.style.width=i+"px",n.style.height=a+"px"}e.style.transition=`clip-path ${o}ms ease-in`,e.style.clipPath="inset(0 0 0 100%)",setTimeout(()=>{t.renderContent(e,s),n&&null!==h&&(n.style.width=h+"px",n.style.height=l+"px"),e.style.transition="none",e.style.clipPath="inset(0 100% 0 0)",e.offsetHeight,e.style.transition=`clip-path ${r}ms ease-out`,e.style.clipPath="inset(0 0 0 0)",n&&setTimeout(()=>{n.style.width="",n.style.height=""},r+100),a&&a()},o)}static renderContent(t,e){if(e&&"object"==typeof e&&e.$$typeof)if("undefined"!=typeof ReactDOM&&ReactDOM.createRoot){const s=ReactDOM.createRoot(t);s.render(e),t._reactRoot=s}else"undefined"!=typeof ReactDOM&&ReactDOM.render?ReactDOM.render(e,t):(console.warn("Pointy: React element passed but ReactDOM not found"),t.innerHTML=String(e));else t.innerHTML=e}constructor(e={}){if(this.classPrefix=e.classPrefix||t.DEFAULT_CLASS_PREFIX,this.classNames=t.generateClassNames(this.classPrefix,e.classSuffixes),e.classNames&&(this.classNames={...this.classNames,...e.classNames}),this.cssVarPrefix=e.cssVarPrefix||this.classPrefix,this.pointerSvg=e.pointerSvg||t.POINTER_SVG,t.injectStyles(this.classNames,this.cssVarPrefix),this.steps=e.steps||[],this.offsetX=void 0!==e.offsetX?e.offsetX:20,this.offsetY=void 0!==e.offsetY?e.offsetY:16,this.tracking=void 0===e.tracking||e.tracking,this.trackingFps=void 0!==e.trackingFps?e.trackingFps:60,this.animationDuration=void 0!==e.animationDuration?e.animationDuration:1e3,this.introFadeDuration=void 0!==e.introFadeDuration?e.introFadeDuration:1e3,this.bubbleFadeDuration=void 0!==e.bubbleFadeDuration?e.bubbleFadeDuration:500,this.messageTransitionDuration=void 0!==e.messageTransitionDuration?e.messageTransitionDuration:500,this.easing=void 0!==e.easing?e.easing:"default",this.resetOnComplete=void 0===e.resetOnComplete||e.resetOnComplete,this.floatingAnimation=void 0===e.floatingAnimation||e.floatingAnimation,this.initialPosition=e.initialPosition||"center",this.initialPositionOffset=void 0!==e.initialPositionOffset?e.initialPositionOffset:32,this.resetPositionOnHide=void 0!==e.resetPositionOnHide&&e.resetPositionOnHide,this.autoplay=e.autoplay||null,this.autoplayEnabled=void 0!==e.autoplayEnabled&&e.autoplayEnabled,this.autoplayWaitForMessages=void 0===e.autoplayWaitForMessages||e.autoplayWaitForMessages,this.hideOnComplete=void 0===e.hideOnComplete||e.hideOnComplete,this.hideOnCompleteDelay=void 0!==e.hideOnCompleteDelay?e.hideOnCompleteDelay:null,this._autoplayTimeoutId=null,this._autoplayPaused=!1,this._messagesCompletedForStep=!1,this._hideOnCompleteTimeoutId=null,this.onStepChange=e.onStepChange,this.onComplete=e.onComplete,this._eventListeners={},this.targetElement=e.target?t.getTargetElement(e.target):null,this.currentStepIndex=0,this.currentMessageIndex=0,this.currentMessages=[],this.messageInterval=e.messageInterval||null,this._messageIntervalId=null,this.isVisible=!1,this.isPointingUp=!0,this.lastTargetY=null,this._targetYHistory=[],this._lastDirectionChangeTime=0,this.manualDirection=null,this.moveTimeout=null,this._hasShownBefore=!1,this.steps.length>0&&(this.targetElement=t.getTargetElement(this.steps[0].target)),this.container=document.createElement("div"),this.container.className=`${this.classNames.container} ${this.classNames.hidden}`,this.container.style.setProperty(`--${this.cssVarPrefix}-duration`,`${this.animationDuration}ms`),this.container.style.setProperty(`--${this.cssVarPrefix}-easing`,this._resolveEasing(this.easing)),this.container.style.setProperty(`--${this.cssVarPrefix}-bubble-fade`,`${this.bubbleFadeDuration}ms`),this.floatingAnimation||(this.container.style.animationPlayState="paused"),this.pointer=document.createElement("div"),this.pointer.className=this.classNames.pointer,t.renderContent(this.pointer,this.pointerSvg),this.bubble=document.createElement("div"),this.bubble.className=this.classNames.bubble,this.bubbleText=document.createElement("span"),this.bubbleText.className=this.classNames.bubbleText,this.steps.length>0){const e=this.steps[0].content;this.currentMessages=Array.isArray(e)?e:[e],t.renderContent(this.bubbleText,this.currentMessages[0])}else{const s=e.content||"";this.currentMessages=Array.isArray(s)?s:[s],t.renderContent(this.bubbleText,this.currentMessages[0])}this.currentMessageIndex=0,this.bubble.appendChild(this.bubbleText),this.container.appendChild(this.pointer),this.container.appendChild(this.bubble),this.updatePosition=this.updatePosition.bind(this),this._trackPosition=this._trackPosition.bind(this),this._lastTrackTime=0,window.addEventListener("resize",this.updatePosition),window.addEventListener("scroll",this.updatePosition)}_trackPosition(){if(this.isVisible&&this.targetElement){if(this.trackingFps>0){const t=performance.now(),e=1e3/this.trackingFps;t-this._lastTrackTime>=e&&(this._lastTrackTime=t,this.updatePosition(),this._emit("track",{target:this.targetElement,timestamp:t}))}else this.updatePosition(),this._emit("track",{target:this.targetElement,timestamp:performance.now()});this._rafId=requestAnimationFrame(this._trackPosition)}else this._rafId=null}_startTracking(){this.tracking&&(this._rafId||this._trackPosition())}_stopTracking(){this._rafId&&(cancelAnimationFrame(this._rafId),this._rafId=null)}updatePosition(){if(!this.targetElement)return;const t=this.targetElement.getBoundingClientRect(),e=window.scrollX,s=window.scrollY;if(null!==this.manualDirection)this.isPointingUp="up"===this.manualDirection;else{const e=t.top+s,i=Date.now();this._targetYHistory.push({y:e,time:i});const n=200;if(this._targetYHistory=this._targetYHistory.filter(t=>i-t.time<n),this._targetYHistory.length>=2){const t=this._targetYHistory[0],e=this._targetYHistory[this._targetYHistory.length-1],s=e.y-t.y;e.time,t.time;const n=30,a=300;if(Math.abs(s)>n&&i-this._lastDirectionChangeTime>a){const t=s<0;t!==this.isPointingUp&&(this.isPointingUp=t,this._lastDirectionChangeTime=i)}}this.lastTargetY=e}let i,n;if(this.isPointingUp)this.pointer.style.transform="rotate(0deg)",i=t.left+e-25+this.offsetX,n=t.bottom+s-8-this.offsetY,this.bubble.style.transform="translateY(28px)";else{this.pointer.style.transform="rotate(90deg)",i=t.left+e-25+this.offsetX,n=t.top+s-25+this.offsetY;const a=this.bubble.offsetHeight||28;this.bubble.style.transform=`translateY(-${a}px)`}this.container.style.left=`${i}px`,this.container.style.top=`${n}px`}show(){if(this._emit("beforeShow",{target:this.targetElement}),this._hideOnCompleteTimeoutId&&(clearTimeout(this._hideOnCompleteTimeoutId),this._hideOnCompleteTimeoutId=null),document.body.contains(this.container)||document.body.appendChild(this.container),!this._hasShownBefore){this._hasShownBefore=!0;const t="first-step"===this.initialPosition,e=this._getInitialPosition(),s=e.x,i=e.y;if(this.container.style.transition=`opacity ${this.introFadeDuration}ms ease`,this.pointer.style.transition="none",this.bubble.style.transition="none",this.bubble.style.opacity="0",this.container.style.left=`${s}px`,this.container.style.top=`${i}px`,t&&void 0!==e.isPointingUp)if(this.isPointingUp=e.isPointingUp,this.isPointingUp)this.pointer.style.transform="rotate(0deg)",this.bubble.style.transform="translateY(28px)";else{this.pointer.style.transform="rotate(90deg)";const t=this.bubble.offsetHeight||28;this.bubble.style.transform=`translateY(-${t}px)`}else this.pointer.style.transform="rotate(0deg)",this.bubble.style.transform="translateY(0)";return this.container.style.display="flex",this.container.offsetHeight,this.container.classList.remove(this.classNames.hidden),this.container.classList.add(this.classNames.visible),this.isVisible=!0,this._emit("introAnimationStart",{duration:this.introFadeDuration,initialPosition:{x:s,y:i}}),void setTimeout(()=>{this._emit("introAnimationEnd",{initialPosition:{x:s,y:i}}),t?(this.container.style.transition="none",this.pointer.style.transition="none",this._startTracking(),this.bubble.style.transition=`opacity ${this.bubbleFadeDuration}ms ease`,this.bubble.style.opacity="1",setTimeout(()=>{this.container.style.transition="",this.pointer.style.transition="",this.bubble.style.transition=""},this.bubbleFadeDuration),this.messageInterval&&this.currentMessages.length>1&&!this._messageIntervalId&&this._startMessageCycle(),this._scheduleAutoplay(),this._emit("show",{target:this.targetElement,isIntro:!0,isFirstStep:!0})):(this.container.style.transition="",this.pointer.style.transition="",this.bubble.style.transition="none",this.updatePosition(),this._startTracking(),setTimeout(()=>{this.bubble.style.transition="",this.bubble.style.opacity="1",this.messageInterval&&this.currentMessages.length>1&&!this._messageIntervalId&&this._startMessageCycle(),this._scheduleAutoplay()},this.animationDuration),this._emit("show",{target:this.targetElement,isIntro:!0,isFirstStep:!1}))},this.introFadeDuration)}this.container.style.display="flex",this.container.offsetHeight,this.container.classList.remove(this.classNames.hidden),this.container.classList.add(this.classNames.visible),this.isVisible=!0,this.updatePosition(),this._startTracking(),this._messageCyclePausedByHide&&this.messageInterval&&this.currentMessages.length>1?(this._startMessageCycle(),this._messageCyclePausedByHide=!1):this.messageInterval&&this.currentMessages.length>1&&!this._messageIntervalId&&this._startMessageCycle(),this._wasAutoplayActiveBeforeHide&&(this._scheduleAutoplay(),this._wasAutoplayActiveBeforeHide=!1),this._emit("show",{target:this.targetElement,isIntro:!1})}hide(){this._emit("beforeHide",{target:this.targetElement}),this.container.classList.remove(this.classNames.visible),this.container.classList.add(this.classNames.hidden),this.isVisible=!1,this.resetPositionOnHide&&(this._hasShownBefore=!1),this._stopTracking(),this._messageIntervalId&&(this._stopMessageCycle(),this._messageCyclePausedByHide=!0),this._wasAutoplayActiveBeforeHide=this.autoplay&&this.autoplayEnabled&&!this._autoplayPaused,this._stopAutoplay(),this._emit("hide",{target:this.targetElement})}restart(){this._emit("beforeRestart",{}),this._hasShownBefore=!1,this.isVisible?(this.container.classList.remove(this.classNames.visible),this.container.classList.add(this.classNames.hidden),this._stopTracking(),this._stopMessageCycle(),this.isVisible=!1,setTimeout(()=>{this.goToStep(0),this.show(),this._emit("restart",{})},50)):(this.goToStep(0),this.show(),this._emit("restart",{}))}destroy(){this._emit("destroy",{}),document.body.contains(this.container)&&document.body.removeChild(this.container),window.removeEventListener("resize",this.updatePosition),window.removeEventListener("scroll",this.updatePosition),this._stopTracking(),this._hideOnCompleteTimeoutId&&(clearTimeout(this._hideOnCompleteTimeoutId),this._hideOnCompleteTimeoutId=null),this._eventListeners={}}reset(e=!0){this._emit("beforeReset",{currentStep:this.currentStepIndex}),this._stopMessageCycle(),this._hideOnCompleteTimeoutId&&(clearTimeout(this._hideOnCompleteTimeoutId),this._hideOnCompleteTimeoutId=null),this.container.classList.add(this.classNames.moving),this.moveTimeout&&clearTimeout(this.moveTimeout);const{x:s,y:i}=this._getInitialPosition();if(this.container.style.left=`${s}px`,this.container.style.top=`${i}px`,this.bubble.style.opacity="0",e&&this.steps.length>0){this.currentStepIndex=0;const e=this.steps[0];this.targetElement=t.getTargetElement(e.target),this.currentMessages=Array.isArray(e.content)?e.content:[e.content],this.currentMessageIndex=0,t.renderContent(this.bubbleText,this.currentMessages[0])}this.moveTimeout=setTimeout(()=>{this.container.classList.remove(this.classNames.moving),this._hasShownBefore=!1,this._emit("reset",{stepIndex:this.currentStepIndex})},this.animationDuration)}setResetOnComplete(t){const e=this.resetOnComplete;e!==t&&(this.resetOnComplete=t,this._emit("resetOnCompleteChange",{from:e,to:t}))}setFloatingAnimation(t){const e=this.floatingAnimation;e!==t&&(this.floatingAnimation=t,this.container.style.animationPlayState=t?"":"paused",this._emit("floatingAnimationChange",{from:e,to:t}))}isFloatingAnimationEnabled(){return this.floatingAnimation}setTracking(t){const e=this.tracking;e!==t&&(this.tracking=t,t&&this.isVisible?this._startTracking():t||this._stopTracking(),this._emit("trackingChange",{from:e,to:t}))}setTrackingFps(t){const e=this.trackingFps;e!==t&&(this.trackingFps=t,this._emit("trackingFpsChange",{from:e,to:t}))}isTrackingEnabled(){return this.tracking}updateContent(e,s=!0){"string"==typeof e&&this.bubbleText.innerHTML===e||(s?t.animateText(this.bubbleText,e,this.messageTransitionDuration,this.bubble,()=>{this.updatePosition()}):(t.renderContent(this.bubbleText,e),this.updatePosition()))}_setMessages(t,e=!1){const s=null!==this._messageIntervalId;this._stopMessageCycle(),this.currentMessages=Array.isArray(t)?t:[t],this.currentMessageIndex=0,this.updateContent(this.currentMessages[0]),e&&this.messageInterval&&this.currentMessages.length>1?this._startMessageCycle():s&&this.currentMessages.length>1&&(this._messageCyclePaused=!0),this._emit("messagesSet",{messages:this.currentMessages,total:this.currentMessages.length,cyclePaused:!0===this._messageCyclePaused})}_startMessageCycle(){this._messagesCompletedForStep=!1,this._messageIntervalId=setInterval(()=>{this.currentMessageIndex===this.currentMessages.length-1&&this.autoplay&&this.autoplayWaitForMessages?(this._stopMessageCycle(),this._messagesCompletedForStep=!0,this._emit("messageCycleComplete",{stepIndex:this.currentStepIndex,totalMessages:this.currentMessages.length}),this._scheduleAutoplayAfterMessages()):this.nextMessage(!0)},this.messageInterval),this._emit("messageCycleStart",{interval:this.messageInterval,totalMessages:this.currentMessages.length})}_stopMessageCycle(){this._messageIntervalId&&(clearInterval(this._messageIntervalId),this._messageIntervalId=null,this._emit("messageCycleStop",{currentIndex:this.currentMessageIndex}))}pauseMessageCycle(){this._messageIntervalId&&(clearInterval(this._messageIntervalId),this._messageIntervalId=null,this._messageCyclePaused=!0,this._emit("messageCyclePause",{currentIndex:this.currentMessageIndex}))}resumeMessageCycle(){return!!(this._messageCyclePaused&&this.messageInterval&&this.currentMessages.length>1)&&(this._messageCyclePaused=!1,this._startMessageCycle(),this._emit("messageCycleResume",{currentIndex:this.currentMessageIndex}),!0)}startMessageCycle(t){return!this._messageIntervalId&&(!(this.currentMessages.length<=1)&&(void 0!==t&&(this.messageInterval=t),!!this.messageInterval&&(this._messageCyclePaused=!1,this._startMessageCycle(),!0)))}stopMessageCycle(){return!!this._messageIntervalId&&(this._stopMessageCycle(),this._messageCyclePaused=!1,!0)}isMessageCycleActive(){return null!==this._messageIntervalId}isMessageCyclePaused(){return!0===this._messageCyclePaused}nextMessage(t=!1){if(this.currentMessages.length<=1)return!1;const e=this.currentMessageIndex;return this.currentMessageIndex=(this.currentMessageIndex+1)%this.currentMessages.length,this.updateContent(this.currentMessages[this.currentMessageIndex]),this._emit("messageChange",{fromIndex:e,toIndex:this.currentMessageIndex,message:this.currentMessages[this.currentMessageIndex],total:this.currentMessages.length,isAuto:t}),!0}prevMessage(){if(this.currentMessages.length<=1)return!1;const t=this.currentMessageIndex;return this.currentMessageIndex=(this.currentMessageIndex-1+this.currentMessages.length)%this.currentMessages.length,this.updateContent(this.currentMessages[this.currentMessageIndex]),this._emit("messageChange",{fromIndex:t,toIndex:this.currentMessageIndex,message:this.currentMessages[this.currentMessageIndex],total:this.currentMessages.length}),!0}goToMessage(t){if(t<0||t>=this.currentMessages.length)return;const e=this.currentMessageIndex;this.currentMessageIndex=t,this.updateContent(this.currentMessages[this.currentMessageIndex]),this._emit("messageChange",{fromIndex:e,toIndex:this.currentMessageIndex,message:this.currentMessages[this.currentMessageIndex],total:this.currentMessages.length})}getCurrentMessage(){return this.currentMessageIndex}getTotalMessages(){return this.currentMessages.length}setContent(e,s=!0){const i=null!==this._messageIntervalId;s?this._setMessages(e,!1):(this._stopMessageCycle(),this.currentMessages=Array.isArray(e)?e:[e],this.currentMessageIndex=0,t.renderContent(this.bubbleText,this.currentMessages[0]),this.updatePosition(),i&&this.currentMessages.length>1&&(this._messageCyclePaused=!0)),this._emit("contentSet",{messages:this.currentMessages,total:this.currentMessages.length,animated:s,cyclePaused:!0===this._messageCyclePaused})}setMessageInterval(t){const e=this.messageInterval;e!==t&&(this.messageInterval=t,this._stopMessageCycle(),t&&this.currentMessages.length>1&&this._startMessageCycle(),this._emit("messageIntervalChange",{from:e,to:t}))}updateTarget(e){const s=this.targetElement;this.targetElement=t.getTargetElement(e),this.updatePosition(),this._emit("targetChange",{from:s,to:this.targetElement})}setOffset(t,e){const s=this.offsetX,i=this.offsetY;s===t&&i===e||(this.offsetX=t,this.offsetY=e,this.updatePosition(),this._emit("offsetChange",{from:{x:s,y:i},to:{x:t,y:e}}))}setAnimationDuration(t){const e=this.animationDuration;e!==t&&(this.animationDuration=t,this.container.style.setProperty(`--${this.cssVarPrefix}-duration`,`${t}ms`),this._emit("animationDurationChange",{from:e,to:t}))}setIntroFadeDuration(t){const e=this.introFadeDuration;e!==t&&(this.introFadeDuration=t,this._emit("introFadeDurationChange",{from:e,to:t}))}setBubbleFadeDuration(t){const e=this.bubbleFadeDuration;e!==t&&(this.bubbleFadeDuration=t,this.container.style.setProperty(`--${this.cssVarPrefix}-bubble-fade`,`${t}ms`),this._emit("bubbleFadeDurationChange",{from:e,to:t}))}_getInitialPosition(){const e=this.initialPositionOffset,s=window.innerWidth,i=window.innerHeight;if("first-step"===this.initialPosition&&this.steps.length>0){const e=this.steps[0],s=t.getTargetElement(e.target);if(s){const t=s.getBoundingClientRect(),i=window.scrollX,n=window.scrollY,a="down"!==e.direction;let o,r;return a?(o=t.left+i-25+this.offsetX,r=t.bottom+n-8-this.offsetY):(o=t.left+i-25+this.offsetX,r=t.top+n-25+this.offsetY),{x:o,y:r,isPointingUp:a}}}if(this.initialPosition&&"string"!=typeof this.initialPosition){const t=this.initialPosition.getBoundingClientRect();return{x:t.left+t.width/2,y:t.top+t.height/2}}if("string"==typeof this.initialPosition&&(this.initialPosition.startsWith("#")||this.initialPosition.startsWith("."))){const t=document.querySelector(this.initialPosition);if(t){const e=t.getBoundingClientRect();return{x:e.left+e.width/2,y:e.top+e.height/2}}}const n={center:{x:s/2,y:i/2},"top-left":{x:e,y:e},"top-center":{x:s/2,y:e},"top-right":{x:s-e,y:e},"middle-left":{x:e,y:i/2},"middle-right":{x:s-e,y:i/2},"bottom-left":{x:e,y:i-e},"bottom-center":{x:s/2,y:i-e},"bottom-right":{x:s-e,y:i-e}};return n[this.initialPosition]||n.center}setInitialPosition(t){const e=["center","top-left","top-center","top-right","middle-left","middle-right","bottom-left","bottom-center","bottom-right","first-step"];if("string"==typeof t&&!t.startsWith("#")&&!t.startsWith(".")&&!e.includes(t))return void console.warn(`Invalid initial position: ${t}. Valid presets: ${e.join(", ")}. Or use a CSS selector or DOM element.`);const s=this.initialPosition;s!==t&&(this.initialPosition=t,this._emit("initialPositionChange",{from:s,to:t}))}animateToInitialPosition(){if(!this.isVisible)return;const{x:t,y:e}=this._getInitialPosition();this._stopTracking(),this.container.style.cssText=`\n position: fixed;\n left: ${t}px;\n top: ${e}px;\n opacity: 0;\n transition: none;\n `,this.bubble.style.opacity="0",this.bubble.style.transition="none",this.container.offsetHeight,this.container.style.transition=`opacity ${this.introFadeDuration}ms ease`,this.container.style.opacity="1",setTimeout(()=>{this.container.style.transition="",this.container.style.cssText="",this.container.style.left=`${t}px`,this.container.style.top=`${e}px`,this.container.offsetHeight,this.updatePosition(),this._startTracking(),setTimeout(()=>{this.bubble.style.transition="",this.bubble.style.opacity="1"},this.animationDuration)},this.introFadeDuration)}setInitialPositionOffset(t){const e=this.initialPositionOffset;e!==t&&(this.initialPositionOffset=t,this._emit("initialPositionOffsetChange",{from:e,to:t}))}_resolveEasing(e){return t.EASINGS[e]?t.EASINGS[e]:e}setEasing(t){const e=this.easing;e!==t&&(this.easing=t,this.container.style.setProperty(`--${this.cssVarPrefix}-easing`,this._resolveEasing(t)),this._emit("easingChange",{from:e,to:t}))}setMessageTransitionDuration(t){const e=this.messageTransitionDuration;e!==t&&(this.messageTransitionDuration=t,this._emit("messageTransitionDurationChange",{from:e,to:t}))}setPointerSvg(e){const s=this.pointerSvg;s!==e&&(this.pointerSvg=e,t.renderContent(this.pointer,e),this._emit("pointerSvgChange",{from:s,to:e}))}getPointerSvg(){return this.pointerSvg}getClassNames(){return{...this.classNames}}getClassPrefix(){return this.classPrefix}getCssVarPrefix(){return this.cssVarPrefix}static getEasingPresets(){return Object.keys(t.EASINGS)}static getInitialPositions(){return["center","top-left","top-center","top-right","middle-left","middle-right","bottom-left","bottom-center","bottom-right","first-step"]}goToStep(e){if(0===this.steps.length||e<0||e>=this.steps.length)return;this._stopAutoplay(),this._messagesCompletedForStep=!1;const s=this.currentStepIndex,i=this.targetElement;this.currentStepIndex=e;const n=this.steps[this.currentStepIndex];this._emit("beforeStepChange",{fromIndex:s,toIndex:e,step:n,fromTarget:i}),this.manualDirection=n.direction||null,this.container.classList.add(this.classNames.moving),this.moveTimeout&&clearTimeout(this.moveTimeout),this._emit("animationStart",{fromTarget:i,toTarget:t.getTargetElement(n.target),type:"step",stepIndex:e}),this.moveTimeout=setTimeout(()=>{this.container.classList.remove(this.classNames.moving),this._emit("moveComplete",{index:e,step:n,target:this.targetElement}),this._emit("animationEnd",{fromTarget:i,toTarget:this.targetElement,type:"step",stepIndex:e}),this._scheduleAutoplay()},this.animationDuration),this._emit("move",{index:e,step:n}),this._setMessages(n.content,!0),this.targetElement=t.getTargetElement(n.target),this.updatePosition(),this._emit("stepChange",{fromIndex:s,toIndex:e,step:n,target:this.targetElement}),this.onStepChange&&this.onStepChange(this.currentStepIndex,n)}_scheduleAutoplay(){if(!this.autoplay||!this.autoplayEnabled||this._autoplayPaused||!this.isVisible)return;const t=this.steps[this.currentStepIndex],e=this.currentMessages.length>1&&this.messageInterval;if(this.autoplayWaitForMessages&&e)return;const s=void 0!==t.duration?t.duration:this.autoplay;s&&s>0&&(this._autoplayTimeoutId=setTimeout(()=>{!this._autoplayPaused&&this.isVisible&&this.autoplayEnabled&&(this._emit("autoplayNext",{fromIndex:this.currentStepIndex,duration:s}),this.next())},s))}_scheduleAutoplayAfterMessages(){if(!this.autoplay||!this.autoplayEnabled||this._autoplayPaused||!this.isVisible)return;this._autoplayTimeoutId=setTimeout(()=>{!this._autoplayPaused&&this.isVisible&&this._messagesCompletedForStep&&(this._emit("autoplayNext",{fromIndex:this.currentStepIndex,afterMessages:!0}),this.next())},300)}_stopAutoplay(){this._autoplayTimeoutId&&(clearTimeout(this._autoplayTimeoutId),this._autoplayTimeoutId=null)}startAutoplay(){this.autoplay&&(this.autoplayEnabled=!0,this._autoplayPaused=!1,this._emit("autoplayStart",{}),this._scheduleAutoplay())}stopAutoplay(){this._stopAutoplay(),this.autoplayEnabled=!1,this._autoplayPaused=!1,this._emit("autoplayStop",{})}pauseAutoplay(){this._stopAutoplay(),this._autoplayPaused=!0,this._emit("autoplayPause",{})}resumeAutoplay(){this._autoplayPaused&&(this._autoplayPaused=!1,this._emit("autoplayResume",{}),this._scheduleAutoplay())}isAutoplayActive(){return this.autoplay&&this.autoplayEnabled&&!this._autoplayPaused}isAutoplayPaused(){return this._autoplayPaused}setAutoplayInterval(t){const e=this.autoplay;e!==t&&(this.autoplay=t,this._emit("autoplayChange",{from:e,to:t}),this.autoplayEnabled&&t&&this.isVisible?(this._stopAutoplay(),this._scheduleAutoplay()):t||(this._stopAutoplay(),this.autoplayEnabled=!1))}setAutoplay(t){this.setAutoplayInterval(t),t&&this.isVisible&&(this.autoplayEnabled=!0,this._autoplayPaused=!1,this.restart())}setAutoplayWaitForMessages(t){const e=this.autoplayWaitForMessages;e!==t&&(this.autoplayWaitForMessages=t,this._emit("autoplayWaitForMessagesChange",{from:e,to:t}))}setHideOnComplete(t){const e=this.hideOnComplete;e!==t&&(this.hideOnComplete=t,this._emit("hideOnCompleteChange",{from:e,to:t}))}setHideOnCompleteDelay(t){const e=this.hideOnCompleteDelay;e!==t&&(this.hideOnCompleteDelay=t,this._emit("hideOnCompleteDelayChange",{from:e,to:t}))}next(){if(0!==this.steps.length)if(this.currentStepIndex<this.steps.length-1)this._emit("next",{fromIndex:this.currentStepIndex,toIndex:this.currentStepIndex+1}),this.goToStep(this.currentStepIndex+1);else{const t=this.autoplay&&this.autoplayEnabled&&!this._autoplayPaused;if(this._emit("complete",{totalSteps:this.steps.length,source:t?"autoplay":"manual"}),t&&(this._stopAutoplay(),this.autoplayEnabled=!1,this._emit("autoplayComplete",{totalSteps:this.steps.length})),this.resetOnComplete){if(this.reset(),this.hideOnComplete){const e=null!==this.hideOnCompleteDelay?this.hideOnCompleteDelay:this.animationDuration,s=t?"autoplay":"manual";this._hideOnCompleteTimeoutId=setTimeout(()=>{this.hide(),this._emit("autoHide",{delay:e,source:s})},this.animationDuration+e)}}else if(this.hideOnComplete){const e=null!==this.hideOnCompleteDelay?this.hideOnCompleteDelay:this.animationDuration,s=t?"autoplay":"manual";this._hideOnCompleteTimeoutId=setTimeout(()=>{this.hide(),this._emit("autoHide",{delay:e,source:s})},e)}this.onComplete&&this.onComplete()}}prev(){0!==this.steps.length&&this.currentStepIndex>0&&(this._emit("prev",{fromIndex:this.currentStepIndex,toIndex:this.currentStepIndex-1}),this.goToStep(this.currentStepIndex-1))}getCurrentStep(){return this.currentStepIndex}getTotalSteps(){return this.steps.length}pointTo(e,s,i){const n=this.targetElement,a=i||"auto";this._emit("beforePointTo",{target:t.getTargetElement(e),content:s,direction:a,fromTarget:n}),this.manualDirection=i||null,this.container.classList.add(this.classNames.moving),this.moveTimeout&&clearTimeout(this.moveTimeout);const o=t.getTargetElement(e);this._emit("animationStart",{fromTarget:n,toTarget:o,type:"pointTo",content:s}),this.targetElement=o,void 0!==s&&this._setMessages(s,!1),this.updatePosition();const r=this.isPointingUp?"up":"down";this.moveTimeout=setTimeout(()=>{this.container.classList.remove(this.classNames.moving),this._emit("pointToComplete",{target:this.targetElement,content:s,direction:r}),this._emit("animationEnd",{fromTarget:n,toTarget:this.targetElement,type:"pointTo",content:s})},this.animationDuration),this._emit("pointTo",{target:this.targetElement,content:s,direction:r}),this.isVisible||this.show()}on(t,e){return this._eventListeners[t]||(this._eventListeners[t]=[]),this._eventListeners[t].push(e),this}off(t,e){return this._eventListeners[t]?(e?this._eventListeners[t]=this._eventListeners[t].filter(t=>t!==e):delete this._eventListeners[t],this):this}_emit(e,s){const i={...s,type:e,pointy:this};this._eventListeners[e]&&this._eventListeners[e].forEach(t=>{try{t(i)}catch(t){console.error(`Pointy: Error in ${e} event handler:`,t)}});const n=t.getEventGroup(e);n&&this._eventListeners[n]&&this._eventListeners[n].forEach(t=>{try{t(i)}catch(t){console.error(`Pointy: Error in ${n} group handler for ${e}:`,t)}}),["*","all"].forEach(t=>{this._eventListeners[t]&&this._eventListeners[t].forEach(t=>{try{t(i)}catch(t){console.error(`Pointy: Error in wildcard handler for ${e}:`,t)}})})}static getEventGroup(e){for(const[s,i]of Object.entries(t.EVENT_GROUPS))if(i.includes(e))return s;return e.endsWith("Change")?"config":null}static getEventsInGroup(e){return t.EVENT_GROUPS[e]||[]}}return t.EVENT_GROUPS={lifecycle:["beforeShow","show","beforeHide","hide","destroy","beforeRestart","restart","beforeReset","reset"],navigation:["beforeStepChange","stepChange","next","prev","complete"],animation:["animationStart","animationEnd","move","moveComplete","introAnimationStart","introAnimationEnd"],content:["contentSet","messagesSet","messageChange"],messageCycle:["messageCycleStart","messageCycleStop","messageCyclePause","messageCycleResume","messageCycleComplete"],pointing:["beforePointTo","pointTo","pointToComplete"],tracking:["track","targetChange","trackingChange","trackingFpsChange"],autoplay:["autoplayStart","autoplayStop","autoplayPause","autoplayResume","autoplayNext","autoplayComplete","autoHide","autoplayChange","autoplayWaitForMessagesChange"]},t});
2
2
  //# sourceMappingURL=pointy.min.js.map